Several tangent vectors on curve

33 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

the cyclist
the cyclist il 14 Mag 2021
Modificato: the cyclist il 14 Mag 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 Commenti
the cyclist
the cyclist il 14 Mag 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 il 17 Mag 2021
I understand, thank you helping!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Programming in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by