Two Plus Two Newer Archives  

Go Back   Two Plus Two Newer Archives > Other Topics > Science, Math, and Philosophy
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 07-12-2007, 10:30 AM
AlexHoops AlexHoops is offline
Senior Member
 
Join Date: May 2005
Posts: 105
Default Graphing in matlab

I need to generate a graph of 36.8cos(x) when x goes between -60 and 80 for my ME class. I have never worked with the matlab graphing function. Does anybody know what commands I will have to type in to generate this graph? Thanks.
Reply With Quote
  #2  
Old 07-12-2007, 11:45 AM
m_the0ry m_the0ry is offline
Senior Member
 
Join Date: Aug 2006
Posts: 790
Default Re: Graphing in matlab

first you generate the independent variable array, which you have designated as being -60 to 80.

x = [-60:.1:80]

this makes our x array span from -60 to 80 with .1 between each array value. This gives us good resolution because there are 2pi/.1 or 20pi samples per oscillation of the wave. If this resolution is not high enough for your application you will need to lower the step size by decreasing the value of the number in the middle of the expression.

Once you have a good array set up, enter

y = 36.8cos(x)

and then

plot(x,y)
Reply With Quote
  #3  
Old 07-12-2007, 11:51 AM
inlemur inlemur is offline
Member
 
Join Date: Aug 2004
Posts: 57
Default Re: Graphing in matlab

[ QUOTE ]


Once you have a good array set up, enter

y = 36.8cos(x)

and then

plot(x,y)

[/ QUOTE ]

This is nitty, but Matlab won't recognize multiplication implicitly. Instead of

y = 36.8cos(x)

use

y = 36.8*cos(x)
Reply With Quote
  #4  
Old 07-12-2007, 01:38 PM
bluesbassman bluesbassman is offline
Senior Member
 
Join Date: Nov 2004
Location: Arlington, Va
Posts: 1,176
Default Re: Graphing in matlab

[ QUOTE ]
[ QUOTE ]


Once you have a good array set up, enter

y = 36.8cos(x)

and then

plot(x,y)

[/ QUOTE ]

This is nitty, but Matlab won't recognize multiplication implicitly. Instead of

y = 36.8cos(x)

use

y = 36.8*cos(x)

[/ QUOTE ]

Another nit: The OP didn't indicate whether the [-60, 80] range in x he desires is degrees or radians. (The former seems more likely given the values.) The matlab trig functions assume radians. So the following line will convert the values in the array x from degrees to radians:

x = x*pi/180;
Reply With Quote
  #5  
Old 07-13-2007, 05:06 AM
Andy Ross Andy Ross is offline
Senior Member
 
Join Date: Jul 2005
Location: South of Heaven
Posts: 287
Default Re: Graphing in matlab

[ QUOTE ]
[ QUOTE ]


Once you have a good array set up, enter

y = 36.8cos(x)

and then

plot(x,y)

[/ QUOTE ]

This is nitty, but Matlab won't recognize multiplication implicitly. Instead of

y = 36.8cos(x)

use

y = 36.8.*cos(x)

[/ QUOTE ]

FYP. Bad habit to not use element by element multiplication.
Reply With Quote
Reply


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


All times are GMT -4. The time now is 06:06 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.