Docsity

Newton's Method for Root-Finding: Implementation and Explanation, Study notes of Mathematics

Toggle sidebar
bg1
ColoState Spring 2009 Math 151 Lecture 4
Newton’s Method for Root-Finding Almost every (nonlinear) equation can be rewritten
as f(x) = 0, where f(x) is assumed to be a differentiable function. We want to find
•a root of this equation;
•or a zero of the function;
•or an intersection of the curve with the x-axis.
Let’s say, an initial guess to the root is x0. The tangent line to the curve at point (x0, f(x0))
is
y=f(x0) + f′(x0)(x−x0).
The Main Idea: Use the intersection of the tangent line with the x-axis as an approximation
to the intersection of the curve with the x-axis. Setting y= 0 in the above tangent line equation,
we obtain
x1=x0−f(x0)
f′(x0),
assuming f′(x0)6= 0. Of course, in that case, the tangent line is parallel to the x-axis, we won’t
have any intersection. Keep doing so, we establish an iterative scheme
xn+1 =xn−f(xn)
f′(xn),(1)
and this is the great Newton’s method.
Implementation of Newton’s Method Implement the Newton’s method as an independent
function (.m file) that has the following format
function [aprx,itr] = newton(fxn,fxnderiv,tol,maxitr,guess)
whereaprx: An approximation to the root
itr: The number of iterations executed
fxn: A generic function for the equation
fxnderiv: A generic function for the derivative
tol: A preset tolerance, say 10−9
maxitr: Maximal number of iterations allowed
guess: An initial guess to the root
pf2

Partial preview of the text

Download Newton's Method for Root-Finding: Implementation and Explanation and more Study notes Mathematics in PDF only on Docsity!

ColoState Spring 2009 Math 151 Lecture 4

Newton’s Method for Root-Finding Almost every (nonlinear) equation can be rewritten as f (x) = 0, where f (x) is assumed to be a differentiable function. We want to find

  • a root of this equation;
  • or a zero of the function;
  • or an intersection of the curve with the x-axis.

Let’s say, an initial guess to the root is x 0. The tangent line to the curve at point (x 0 , f (x 0 )) is y = f (x 0 ) + f ′(x 0 )(x − x 0 ).

The Main Idea: Use the intersection of the tangent line with the x-axis as an approximation to the intersection of the curve with the x-axis. Setting y = 0 in the above tangent line equation, we obtain

x 1 = x 0 −

f (x 0 ) f ′(x 0 )

assuming f ′(x 0 ) 6 = 0. Of course, in that case, the tangent line is parallel to the x-axis, we won’t have any intersection. Keep doing so, we establish an iterative scheme

xn+1 = xn −

f (xn) f ′(xn)

and this is the great Newton’s method.

Implementation of Newton’s Method Implement the Newton’s method as an independent function (.m file) that has the following format

function [aprx,itr] = newton(fxn,fxnderiv,tol,maxitr,guess)

where aprx: An approximation to the root itr: The number of iterations executed fxn: A generic function for the equation fxnderiv: A generic function for the derivative tol: A preset tolerance, say 10−^9 maxitr: Maximal number of iterations allowed guess: An initial guess to the root

Things to Consider When Implementing the Newton’s Method

  • Use for ... end or while ... end for iterations?
  • Use feval for the two generic functions: fxn and fxnderiv
  • Store all successive approximations into a vector?
  • Handle the exception case: divided by zero

Examples of using inline to define a function:

myfxn = inline(’x.^3-2x+2’, ’x’); myfxnderiv = inline(’3x.^2-2’, ’x’);