How to plot thisfunction?

2 visualizaciones (últimos 30 días)
Yagnaseni Roy
Yagnaseni Roy el 6 de Mayo de 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 comentario
Walter Roberson
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.

Iniciar sesión para comentar.

Respuesta aceptada

the cyclist
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
Yagnaseni Roy
Yagnaseni Roy el 6 de Mayo de 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 el 7 de Mayo de 2012
I edited my answer in response to the comment.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Function Creation en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by