Several tangent vectors on curve

32 vues (au cours des 30 derniers jours)
Viktor Karlsson
Viktor Karlsson le 14 Mai 2021
Commenté : Viktor Karlsson le 17 Mai 2021
Hello,
I have the following curve plotted:
Now, I want 10 tangent vectors along this curve and I can't seem to figure out how to write the code for this to work. I wrote the following:
t = linspace(-2.5,2.5,100);
x = t.^3 - 4*t;
y = t.^2;
plot(x,y,'LineWidth',2)
axis equal
hold on
i=1:10:100;
ts=t(i);
xs=x(i);
ys=y(i);
tx = ts.^3 -4*ts;
ty = ts.^2;
quiver(tx,ty,xs,ys,'LineWidth',2,'Color','r')
hold off
and the result is.. not quite it:
Any help or advice is appreciated.

Réponse acceptée

the cyclist
the cyclist le 14 Mai 2021
Modifié(e) : the cyclist le 14 Mai 2021
Well, you never actually calculated the tangent, so it is not that surprising you didn't get the correct result.
t = linspace(-2.5,2.5,100);
x = t.^3 - 4*t;
y = t.^2;
dydt = 2*t;
dxdt = 3*t.^2 - 4;
dydx = dydt./dxdt;
i=1:10:100;
ts=t(i);
xs=ones(size(i));
ys=dydx(i);
tx = ts.^3 -4*ts;
ty = ts.^2;
figure
hold on
plot(x,y,'LineWidth',2)
quiver(tx,ty,xs,ys,'LineWidth',2,'Color','r')
axis equal
Apologies for rearranging your code to my liking. See this page for the math of calculating the tangent of a parametric equation. (You'll need to be careful if dx/dt is ever zero, because you divide by that.)
Also, I was lazy and just set the length of the x-component of the tangent vector to (positive) 1, then calculated the y-component. You probably want something less lazy.
  3 commentaires
the cyclist
the cyclist le 14 Mai 2021
As I mentioned, I always defined the x-component of the tangent vector as +1; therefore, it will always be toward the right.
The parametric equation has no inherent "direction", and the tangent line extends in both directions from any given point.
Viktor Karlsson
Viktor Karlsson le 17 Mai 2021
I understand, thank you helping!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by