Filter löschen
Filter löschen

Plotting the parametric curve and its second derivative

3 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Star Strider
Star Strider am 9 Nov. 2021
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 Kommentare
Szabolcs Simon-Guth
Szabolcs Simon-Guth am 9 Nov. 2021
Thank you! I have not noticed that little error. Much appriciated! :)
Star Strider
Star Strider am 9 Nov. 2021
As always, my pleasure!
.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by