Newtons Method

Description

Newton's Method is a way to solve equations that cannot typically be solved using ordinary techniques of algebra. Newton's method is a series of numerical approximations based that successively get more accurate. Consider the equation $\cos x = x-1$. Normally we would have no way to solve this equation using algebra, but we can make the equation be $\cos x - x + 1 = 0$. Then using the formula

(1)
\begin{align} x_{ n+1 } = x_n - \frac{ f(x_n) }{ f'(x_n) } \end{align}

we can get each successive approximation. Note that this will only work as long as your initial approximation is near the root you are trying to solve for. The Sage code below will approximate the solution for the equation $\cos x = x-1$ with an initial approximation of $x_0 = 1$.

Sage Cell

Code

f(x) = cos(x) - x + 1
df(x) = diff(f, x)
def newton(f, df, x0, e, j):
delta=abs(f(x0))
while delta>e:
print "Iteration: " , j
print "x_" , j-1 , " = " , numerical_approx(x0)
print "The Error for f(x_" , j-1 , ") is " , numerical_approx(f(x0))
x0 = x0 - (f(x0) / df(x0))
j = j + 1
delta=abs(f(x0))
newton(f, df, 1, .00001, 1)

None

Primary Tags:

Secondary Tags:

Related Cells

Any related cells go here. Provide a link to the page containing the information about the cell.