How to plot thisfunction?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentario
Walter Roberson
el 6 de Mayo de 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.
Respuesta aceptada
the cyclist
el 6 de Mayo de 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Function Creation en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!