필터 지우기
필터 지우기

Plotting the parametric curve and its second derivative

조회 수: 3 (최근 30일)
Szabolcs Simon-Guth
Szabolcs Simon-Guth 2021년 11월 9일
댓글: Star Strider 2021년 11월 9일
Hi everyone!
I would like to plot a parametric curve of a two-variable fuction (parameters x and y, in the code below), along with its second derivative (ax, ay in the code below).
I have written the code below, however when I run the code I get an error stating: Arrays have incompetible sizes for this operation. This error applys to the line where I have defined the second derivative (i.e.: ax, ay). I do not understand what the problem is. Could anyone give me a hint? Thank you very much for all help in advance!
The code:
t = linspace(0, 3, 1000);
% Plotting the function
k = exp(-t);
x = k.*(cos(10*t)+0.3*sin(10*t));
y = k.*(sin(10*t));
plot(x,y, '-k', 'LineWidth', 1.5)
axis equal
hold on
% Picking 100 points in the function
i = 1:10:1000;
ts = t(i);
xs = x(i);
ys = y(i);
% Calculating and plotting the second derivative at the given 100 points
ax = k.*((-9.7.*sin(10.*ts)-(105.*cos(10.*ts))));
ay = k.*((99.*sin(10.*ts)+(20.*cos(10.*ts))));
quiver(xs,ys,ax,ay, 'LineWidth',2,'Color','r')
hold off

채택된 답변

Star Strider
Star Strider 2021년 11월 9일
Is that is necessary to subscript ‘k’ so that it is the same size as the other elements in the calculation —
t = linspace(0, 3, 1000);
% Plotting the function
k = exp(-t);
x = k.*(cos(10*t)+0.3*sin(10*t));
y = k.*(sin(10*t));
plot(x,y, '-k', 'LineWidth', 1.5)
axis equal
hold on
% Picking 100 points in the function
i = 1:10:1000;
ts = t(i);
xs = x(i);
ys = y(i);
% Calculating and plotting the second derivative at the given 100 points
ax = k(i).*((-9.7.*sin(10.*ts)-(105.*cos(10.*ts))));
ay = k(i).*((99.*sin(10.*ts)+(20.*cos(10.*ts))));
quiver(xs,ys,ax,ay, 'LineWidth',2,'Color','r')
hold off
.
  댓글 수: 2
Szabolcs Simon-Guth
Szabolcs Simon-Guth 2021년 11월 9일
Thank you! I have not noticed that little error. Much appriciated! :)
Star Strider
Star Strider 2021년 11월 9일
As always, my pleasure!
.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by