View Full Version : Plotting a stream function in matlab

dukebound85

Oct 30, 2010, 04:05 PM

How does one do this?

I am trying to plot

PSI = Acos(6x)-Uy where A=1 and U=1 over an x range of -2000-200 and y from -2000-2000

My code is this and it is giving me an error.

x = -2000:1:2000;

y = -2000:1:2000;

si = zeros(x,y);

for x = -2000:1:2000

for y = -2000:1:2000

si(x,y) = cos(6*x)-y;

end

end

plot(si)

Thanks for any help:)

SidBala

Oct 30, 2010, 04:55 PM

What is the error?

I am not sure what you are trying to do here. Are you trying to make a 3D graph of cos(6*x) - y over x = [-2000,2000] and y = [-2000,2000] ?

dukebound85

Oct 30, 2010, 05:28 PM

What is the error?

I am not sure what you are trying to do here. Are you trying to make a 3D graph of cos(6*x) - y over x = [-2000,2000] and y = [-2000,2000] ?

This is my error

??? Attempted to access si(-2000,-2000); index must be a positive integer or logical.

Error in ==> si5 at 6

si(x,y) = cos(6*x)-y;

Essentially, I want to plot the si function over many values of x's and y's that will result in somewhat parrallel plots so to speak.

Something that looks like this

http://upload.wikimedia.org/wikipedia/commons/thumb/e/e0/Particle_mass_plot.png/650px-Particle_mass_plot.png

Berlepsch

Oct 31, 2010, 08:20 AM

I never used Matlab, but from the error description

??? Attempted to access si(-2000,-2000); index must be a positive integer or logical.

Error in ==> si5 at 6

si(x,y) = cos(6*x)-y;

it seems clear that the x,y in si(x,y) are indexes for a two-dimensional array and must be larger than zero. try the following:

for x = 0:1:4000

for y = 0:1:4000

si(x,y) = cos(6*(x-2000))-(y-2000);

crackpip

Oct 31, 2010, 01:03 PM

In MATLAB arrays always have a lower bound of 1. Your for loops have to be adjusted. Also I think contour() is more suitable instead of plot(). Then you can specify the x- and y-axis units.

crackpip