In [7]:
import matplotlib.pyplot as plt
In [8]:
def f(x):
y = 1*(x**2) - (22*x) + 150
return y
def calcDerivative(x):
return 2 * x - 22
def getTangentLine(m, x, x1, y1):
y = m * x - m * x1 + y1
return y
In [9]:
x = range(3, 20)
x
Out[9]:
In [10]:
y = [f(i) for i in x]
y
Out[10]:
In [11]:
point1_x = 11.4
point1_y = f(point1_x)
m = calcDerivative(point1_x)
tangent = [ getTangentLine(m, i, point1_x, point1_y) for i in x]
In [14]:
plt.plot(x, y)
plt.plot(x, tangent)
plt.plot(point1_x, getTangentLine(m, point1_x, point1_x, point1_y), 'ro')
plt.show()
In [ ]:
In [ ]: