How to plot thisfunction?

1 次查看(过去 30 天)
The function to be plotted is:
50*(y*(28.065*cos(60[1/s]*t+0.2094395101999999[1/m]*x)+22.7058*cos(2*(60[1/s]*t+0.2094395101999999[1/m]*x))+15.1368*cos(3*(60[1/s]*t+0.2094395101999999[1/m]*x))+7.014*cos(4*(60[1/s]*t+0.2094395101999999[1/m]*x)))/1[m])[m/s]
As you can see, its a function of three variables, x,y and t.....
However I need it to vary only between 0 to 30 w.r.t x...and the y and t values can be anything...what is the format of the code to be used?
  1 个评论
Walter Roberson
Walter Roberson 2012-5-6
First you rewrite the expression in terms of MATLAB operations. In particular, in MATLAB, [] is used for building arrays, and is not an arithmetic operator.

请先登录,再进行评论。

采纳的回答

the cyclist
the cyclist 2012-5-6
First, as Walter mentions, you need to rewrite the definition of your function in MATLAB syntax.
Here, I assumed that you wanted x,v, and t on a simple grid, and plot them for all combinations.
[Also, it looks like the terms you have in square brackets are just units, so I simply took them out.]
xvec = 1:10;
yvec = 1:20;
tvec = 1:5;
[x,y,t] = ndgrid(xvec,yvec,tvec);
f = 50*(y.*(28.065*cos(60*t+0.2094395101999999*x)+22.7058*cos(2*(60*t+0.2094395101999999*x))+15.1368*cos(3*(60*t+0.2094395101999999*x))+7.014*cos(4*(60*t+0.2094395101999999*x)))/1);
But now you have a function three variables, so you want a plot over a four-dimensional space: (x,y,t,f).
What kind of plot are you hoping to see from that?
EDIT: Here's a version of the plotting that selects just one value of y and t, as you suggest:
xvec = 0.1:0.1:5;
yvec = 10;
tvec = 1;
[x,y,t] = ndgrid(xvec,yvec,tvec);
f = 50*(y.*(28.065*cos(60*t+0.2094395101999999*x)+22.7058*cos(2*(60*t+0.2094395101999999*x))+15.1368*cos(3*(60*t+0.2094395101999999*x))+7.014*cos(4*(60*t+0.2094395101999999*x)))/1);
figure
plot(x,f)
  2 个评论
Yagnaseni Roy
Yagnaseni Roy 2012-5-6
Ya, you're right that the terms in the square brackets are only units and so u can just take them out.
The y and t values could be fixed at particular values, say y=10 and t=1....and now we can plot f vs x.
the cyclist
the cyclist 2012-5-7
I edited my answer in response to the comment.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Function Creation 的更多信息

标签

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by