Plotting the parametric curve and its second derivative

3 次查看(过去 30 天)
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
.

更多回答(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