Filter löschen
Filter löschen

How to plot thisfunction?

1 Ansicht (letzte 30 Tage)
Yagnaseni Roy
Yagnaseni Roy am 6 Mai 2012
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 Kommentar
Walter Roberson
Walter Roberson am 6 Mai 2012
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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

the cyclist
the cyclist am 6 Mai 2012
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 Kommentare
Yagnaseni Roy
Yagnaseni Roy am 6 Mai 2012
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 am 7 Mai 2012
I edited my answer in response to the comment.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by