In [19]:
%matplotlib inline

import matplotlib
import numpy as np
import matplotlib.pyplot as pt
In [20]:
a = 17.09
b = 9.79
c = 0.6137
d = 0.9324
e = .4565

def f(x):
    return a*x**4 + b*x**3 + c*x**2 + d*x + e

def df(x):
    return 4*a*x**3 + 3*b*x**2 + 2*c*x + d

def d2f(x):
    return 3*4*a*x**2 + 2*3*b*x + 2*c
In [21]:
xmesh = np.linspace(-1,0.5, 100)

pt.ylim([-1,3])
pt.plot(xmesh,f(xmesh))
Out[21]:
[<matplotlib.lines.Line2D at 0x11524bb70>]
In [22]:
x = 0.3 #initial guess of minimum
In [23]:
dfx = df(x)
d2fx = d2f(x)

#newton step
xnew = x - dfx/d2fx

#plot approximate function
pt.plot(xmesh, f(xmesh))
pt.plot(xmesh, f(x) + dfx*(xmesh-x) + 0.5*d2fx*(xmesh-x)**2)
pt.plot(x, f(x), "o")
pt.plot(xnew, f(xnew),"o",color = "green")
pt.ylim([-1, 3])

#update guess
x = xnew
print(x)
0.1448092294660998
In [ ]: