PDA

View Full Version : Graphing in matlab


AlexHoops
07-12-2007, 10:30 AM
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.

m_the0ry
07-12-2007, 11:45 AM
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)

inlemur
07-12-2007, 11:51 AM
[ 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)

bluesbassman
07-12-2007, 01:38 PM
[ 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;

Andy Ross
07-13-2007, 05:06 AM
[ 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.