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]:
[3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]

In [10]:
y = [f(i) for i in x]
y


Out[10]:
[93, 78, 65, 54, 45, 38, 33, 30, 29, 30, 33, 38, 45, 54, 65, 78, 93]

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 [ ]: