Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Oct 30, 2010, 04:05 PM   #1
dukebound85
macrumors P6
 
dukebound85's Avatar
 
Join Date: Jul 2005
Location: 5045 feet above seal level
Plotting a stream function in matlab

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
dukebound85 is offline   0 Reply With Quote
Old Oct 30, 2010, 04:55 PM   #2
SidBala
macrumors 6502a
 
Join Date: Jun 2010
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] ?
SidBala is offline   0 Reply With Quote
Old Oct 30, 2010, 05:28 PM   #3
dukebound85
Thread Starter
macrumors P6
 
dukebound85's Avatar
 
Join Date: Jul 2005
Location: 5045 feet above seal level
Quote:
Originally Posted by SidBala View Post
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
Quote:
??? 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/wikipedi..._mass_plot.png
dukebound85 is offline   0 Reply With Quote
Old Oct 31, 2010, 08:20 AM   #4
Berlepsch
macrumors 6502
 
Join Date: Oct 2007
I never used Matlab, but from the error description

Quote:
??? 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);
__________________
"Everyone knows the inch is better than the centimeter, because it is bigger."
Berlepsch is online now   0 Reply With Quote
Old Oct 31, 2010, 01:03 PM   #5
crackpip
macrumors regular
 
Join Date: Jul 2002
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
crackpip is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
'MobileMe iDisk' Music Streaming Functionality Gaining Renewed Attention MacRumors MacRumors.com News Discussion 44 Aug 5, 2010 02:02 PM
Will a jailbroken US Iphone 4 fully function in Canada & continue to function in US? ranthonyt Jailbreaks and iOS Hacks 2 Jun 17, 2010 08:32 PM
Global Variables? or accessing one variable in one function in another function? MythicFrost iPhone/iPad Programming 2 Dec 19, 2009 10:41 PM
Plotting three variable data in a triangular formation serralves Mac Programming 9 Aug 31, 2007 05:03 AM
Functions in Matlab Eraserhead Mac Programming 9 Feb 6, 2007 05:32 AM


All times are GMT -5. The time now is 08:26 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC