Scroll to Top

Virtual Math Learning Center

Virtual Math Learning Center Texas A&M University Virtual Math Learning Center

Tangents to Parametrized Curves at a Given Point in Python

Author: David Manuel

This video shows how to find a tangent line to a parametric curve at a point by finding the value of the parameter at that point and then finding the derivative. Then both the parametric curve and its tangent line are plotted using Python. 

Transcript 17

Problem: Find the first several derivatives of \(f(x)=\frac{1}{x}\) and generalize a pattern for the nth derivative.

Python Code:
from sympy import *

x,t=symbols('x t')
xt=cos(t)**3
yt=sin(t)**3
eq1=xt-1/27
# To get exact answers, use the Rational command: eq1=xt-Rational(1,27) 
eq2=yt-16*sqrt(2)/27
# To get exact answers, use the Rational command: eq2=yt-Rational(16,27)*sqrt(2)
tval=solve([eq1,eq2],t)
print(tval)

dydx=diff(yt,t)/diff(xt,t)
print('dy/dx=',dydx)
m=dydx.subs(t,tval[0][0])
print(m)
tanline=16*sqrt(2)/27+m*(x-1/27)
print('The equation of the tangent line is y=',tanline.evalf())

matplotlib notebook

pcurve=plot_parametric(xt,yt,(t,0,pi/2))
pcurve.extend(plot(tanline,(x,0,1)))
pcurve.show()

Open Python Notebook File

See more videos from this section