Newton's Method

Dr. Kevin G. TeBeest
Kettering University

Copyright © 2002−2023 Kevin G. TeBeest. All rights reserved.


NOTE: This is NOT the Maple code for Newton's method.
This is merely DEMONSTRATING what Newton's method is doing.

After starting Maple, you must first load Maple's "student" library of commands:

> with(student) :

Define the function f( x ) . As an example, we'll use function f(x) = cos(ln(x))

> f := x −> evalf( cos( ln(x) ) ) ;
   The evalf command automatically converts the results to floating point (decimal) form any time function f is evaluated.

f := proc (x) options operator, arrow; cos(ln(x)) e...

Determine the derivative f '( x ) and store it AS A FUNCTION in fp (using the unapply command):

> fp := unapply( diff( f(x) , x ) , x ) ;

fp := proc (x) options operator, arrow; -sin(ln(x))...

Plot function f(x) to determine roughly where its zero is. We'll plot it on the x interval [0,10] and restict the y range to [−1,1]:

> plot( f(x), x = 0.0 .. 10.0, −1.0 .. 1.0, thickness = 4 ) ;

[Maple Plot]

We see that the zero lies near x = 5.
Also, remember to STAY AWAY from the critical value near x = 1.5.


Although x = 5 would be an excellent starting value, to demonstrate Newton's method we'll use a starting value of x = 9.5

> x0 := 9.5 ;

x0 := 9.5

FOR ILLUSTRATION PURPOSES ONLY, here we will use Maple's "showtangent" command to automatically plot function f (x) and its tangent line at x0 = 9.5 :
To obtain a clean plot, we'll restrict the x interval (horizontal range) to [0,10] and the y interval (vertical range) to [−1,1].

> showtangent( f(x), x = x0, x = 0.0 .. 10.0, −1.0 .. 1.0, thickness = 4 ) ;

[Maple Plot]


Now use Newton's method to calculate x1, the first approximation to z :

> x1 := x0 − f(x0) / fp(x0) ;

x1 := 1.809928775

FOR ILLUSTRATION PURPOSES ONLY, here we will use Maple's "showtangent" command to automatically plot function f (x) and its tangent line at x1.
To obtain a clean plot, we'll restrict the
x interval (horizontal range) to [0,10] and the y interval (vertical range) to [−1,1].

> showtangent( f(x), x = x1, x = 0.0 .. 10.0, −1.0 .. 1.0, thickness = 4 ) ;

[Maple Plot]


Now use Newton's method to calculate x2, the second approximation to z :

> x2 := x1 − f(x1) / fp(x1) ;

x2 := 4.493979009

FOR ILLUSTRATION PURPOSES ONLY, here we will use Maple's "showtangent" command to automatically plot function f (x) and its tangent line at x2.
To obtain a clean plot, we'll restrict the x interval (horizontal range) to [0,10] and the y interval (vertical range) to [−1,1], or we may "zoom in" by changing these ranges.

> showtangent( f(x), x = x2, x = 0.0 .. 10.0, −1.0 .. 1.0, thickness = 4 ) ;

[Maple Plot]


Now use Newton's method to calculate x3, the third approximation to z :

> x3 := x2 − f(x2) / fp(x2) ;

x3 := 4.800302537

FOR ILLUSTRATION PURPOSES ONLY, here we will use Maple's "showtangent" command to automatically plot function f (x) and its tangent line at x3.
To obtain a clean plot, we'll restrict the x interval to [0,10] and the y interval to [−1,1], or we may "zoom in" by changing these ranges.

> showtangent( f(x), x = x3, x = 0.0 .. 10.0, −1.0 .. 1.0, thickness = 4 ) ;

[Maple Plot]


We may use Maple's "fsolve" command to approximate the zero automatically. We'll search on the interval [2,8].

> correct_zero := fsolve( f(x), x = 2.0 .. 8.0 ) ;

correct_zero := 4.810477381


Return to Section 1.3 assignment

Return to course web site

Dr. Kevin G. TeBeest
Applied Mathematics
Kettering University