MATLAB: Tangent line of a parametric curve

MATLAB and Simulink Student Suiteparametricslopetangent

How do I program MATLAB to determine the equation of a line tangent to a parametric curve?
I see plenty of videos/threads on plotting parametrics, but I havent found any on using MATLAB to perform the deriving of a tangent equation.

Best Answer

The function you have and the result you want are not obvious.
Try this:
t = linspace(0, 2*pi); % Create Curve

y = sin(t); % Create Curve
Point = randi(numel(t)); % Random Point On Curve
dydt = gradient(y) ./ gradient(t); % Derivative
b = y(Point) - dydt(Point)*t(Point); % Intercept
idxv = max(1,Point-10):min(numel(t),Point+10); % Index Vector
Tan = dydt(Point)*t(idxv) + b;
figure
plot(t, y)
hold on
plot(t(idxv),Tan, '-r')
hold off
grid