plotting function over interval
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jente Marien
el 4 de Mzo. de 2017
Comentada: John BG
el 5 de Mzo. de 2017
a=62; b=95;
v = linspace(-pi, pi, 1000); y = @(x) (3*x.^2.*sin(a*x))/(x.^2+b); plot(y,v)
how is it possible to plot this function?
0 comentarios
Respuesta aceptada
John BG
el 4 de Mzo. de 2017
Editada: John BG
el 4 de Mzo. de 2017
Hi Marien
1.
the new function fplot works, although with a speed warning, that is not that critical
a=62; b=95;
v = linspace(-pi, pi, 1000);
y = @(x) (3*x.^2.*sin(a*x))/(x.^2+b);
fplot(y)
.
the thing is, with fplot MATLAB has to decide where to start and stop, and because the signal is energy unstable, with time either side it doesn't tend to null, then MATLAB makes an axis limit decision that may not be your preferred choice.
fplot also works without the element wise dots
y = @(x) (3*x^2*sin(a*x))/(x^2+b);
same result as above
2.
with plot, you have to decide the reference vector and the step resolution, which is good, because you decide their values.
dx=.000001;x=[-5:dx:5];y= (3*x.^2.*sin(a*x))./(x.^2+b);grid on
similar plot as above.
Note that I have added a dot ahead of the ' /' operator of your function expression, otherwise the plot goes empty because without that dot the resulting y is a single scalar.
if you find this answer useful would you please be so kind to mark my answer as Accepted Answer?
To any other reader, please if you find this answer of any help solving your question,
please click on the thumbs-up vote link,
thanks in advance
John BG
Más respuestas (1)
Star Strider
el 4 de Mzo. de 2017
You have to call the function in the plot statement in order to plot it.
The Code —
a=62; b=95;
v = linspace(-pi, pi, 1000);
y = @(x) (3*x.^2.*sin(a*x))./(x.^2+b);
figure(1)
subplot(1,2,1)
plot(y(v),v)
xlabel('y(v)')
ylabel('v')
subplot(1,2,2)
plot(v, y(v))
xlabel('v')
ylabel('y(v)')
The left subplot plots ‘v’ against ‘y(v)’, and the right subplot plots ‘y(v)’ against ‘v’.
The Plots —
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!