Newton's Method

(updated: )
  1. 1. Formula
  2. 2. Example

Formula

$$ x_{i + 1} = x_i - \frac{f(x_i)}{f’(x_i)} $$
Where f'(x) is the derivative.

Example

Say you want to find the value of x in $ x^3 + x - 1 = 0 $

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
def f(x):
return x**3 + x -1
def d(x): # derivative
return 3*x**2 + 1
def newton(x, e):
while True:
if d(x) == 0:
return x
old = x
x = x - f(x)/d(x)
if abs(x - old) <= e:
return x
if __name__ == "__main__":
print newton(12.00, 0.0000001)