Hello, I have a problem with the following code;
x=linspace(0,2*pi,100);
for t=1:length(x)
f=@(x) 2+sin(5*x(t)+2.2.*cos(5.*x(t))); hold on
plot(x,f(x),'b')
end
If i change in the plot argument to 'bo-' I get alot of wierd lines of circles not in par with what im trying to accomplish, namely to plot the function r(t)=2+sin(5t+2.2cos(5t)), 0<t<2pi.

 採用された回答

Walter Roberson
Walter Roberson 2017 年 10 月 13 日

0 投票

t = linspace(0,2*pi,100);
r = 2 + sin(5 * t + 2.2 * cos(5 * t));
plot(t, r)

2 件のコメント

Gustav Hallberg
Gustav Hallberg 2017 年 10 月 13 日
Why won't
t=linspace(0,2*pi,1000)
work for a more precise curve? Shouldn't r also change length?
Walter Roberson
Walter Roberson 2017 年 10 月 13 日
It does work, provided that you recalculate r after you change t, and call plot() to update the drawing.

サインインしてコメントする。

その他の回答 (1 件)

Image Analyst
Image Analyst 2017 年 10 月 13 日

0 投票

Try this:
x=linspace(0,2*pi,100);
y = zeros(1, length(x));
f=@(x, t) 2+sin(5*x(t)+2.2.*cos(5.*x(t)));
for t=1:length(x)
t
y(t) = f(x, t);
plot(x(1:t), y(1:t), 'b*-')
hold on
grid on;
drawnow;
pause(0.1);
end

カテゴリ

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by