Scroll to Top

Virtual Math Learning Center

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

Finding and Graphing Tangent Lines to a Curve in Python

Author: David Manuel

In this video, it is shown how find the tangent line to a curve in Python. The presenter shows how to substitute a value into the function, find the value of the derivative at the point, and find the equation of the tangent line. The function and the tangent line are then graphed together to verify the tangent line is correct.

Transcript 12

Problem: Find the equation of the tangent line when \(x=80\) for the function
\[f(x)=\dfrac{e^{(x-75)^2/200}}{10\sqrt{2\pi}}\]

Python Code: 
from sympy import *

x=symbols('x')
f=exp((x-75)**2/200)/(10*sqrt(2*pi))
y0=f.subs(x,80)
df=diff(f,x)
m=df.subs(x,80)
tanline=y0+m*(x-80)
print('The equation of the tangent line is y=',tanline.evalf())

matplotlib notebook

plot((f,(x,60,100)),(tanline,(x,60,100)))

Open Python Notebook File

See more videos from this section