plotting function over interval

조회 수: 2 (최근 30일)
Jente Marien
Jente Marien 2017년 3월 4일
댓글: John BG 2017년 3월 5일
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?

채택된 답변

John BG
John BG 2017년 3월 4일
편집: John BG 2017년 3월 4일
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

추가 답변 (1개)

Star Strider
Star Strider 2017년 3월 4일
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

카테고리

Help CenterFile Exchange에서 Graphics에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by