# Plotting a stream function in matlab

Discussion in 'Mac Programming' started by dukebound85, Oct 30, 2010.

1. ### dukebound85 macrumors P6

Joined:
Jul 17, 2005
Location:
5045 feet above sea level
#1
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

2. ### SidBala macrumors 6502a

Joined:
Jun 27, 2010
#2
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] ?

3. ### dukebound85 thread starter macrumors P6

Joined:
Jul 17, 2005
Location:
5045 feet above sea level
#3
This is my error
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

4. ### Berlepsch macrumors 6502

Joined:
Oct 22, 2007
#4
I never used Matlab, but from the error description

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);

5. ### crackpip macrumors regular

Joined:
Jul 23, 2002
#5
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