Borrar filtros
Borrar filtros

Plotting the parametric curve and its second derivative

3 visualizaciones (últimos 30 días)
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

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by