Newton-Raphson Method

This work sheet features two approaches. The first one introduces loops in Maple and shows how they can be used with Newton's method to find solutions to equations. The second approach uses an animation to demonstrate Newton's method visually.

EXAMPLE 1 (numerical approach)

Assume you want to solve 11 - x^2 = 0. Use the Enter Expression button on MenuMaple and select the function option . Enter f as the name of the function, x as the independent variable, and 11 - x^2 as the expression.

> f:=x->11-x^2;

[Maple Math]

From the calculus menu of MenuMaple find the derivative of f with respect to x and call the result df

> df:=D(f);

[Maple Math]

We will use an initial value of 1 for xn in Newton's method.

> xn:=1;

[Maple Math]

The following loop will perform 7 iterations of Newton's method. Each time the new value of xn is based on the old value of xn by means of xn - f(xn)/f '(xn). To insure that decimal values are obtained evalf is used. To get the loop to execute place the cursor any where inside the red commands and press the enter key.

> for i from 1 to 7 do
> xn:=evalf(xn-f(xn)/df(xn));
> od;

[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]

Change the first value of xn to -1 and re-execute the loop. What do you get now?

> xn:=-1;

[Maple Math]

> for i from 1 to 7 do
> xn:=evalf(xn-f(xn)/df(xn));
> od;

[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]

This next command loads the package math191 which contains a custom Maple command that will create an animation (of the first four steps) of Newton's method.

> with(math191):
> newtonraphson(f(x),x=1);

[Maple Plot]

EXAMPLE 2

Make changes in example 1 so that you can find the solution to
2*x - 5 - sin(x) = 0. You'll need to modify the expression used in f, find its derivative, perhaps change the starting value of xn, and then re-execute the loop.

> f:=x->2*x-5-sin(x);

[Maple Math]

> df:=D(f);

[Maple Math]

> xn:=0;

[Maple Math]

> for i from 1 to 7 do
> xn:=evalf(xn-f(xn)/df(xn));
> od;

[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]

> newtonraphson(f(x),x=0);

[Maple Plot]

EXAMPLE 3

Make changes in example 1 so that you can try to find the solution to
x^(1/3)=0 by Newton's method. In order to be sure of getting real values use surd(x,3) in place of x^(1/3). What happens?

> f:=x->surd(x,3);

[Maple Math]

> df:=D(f);

[Maple Math]

> xn:=1;

[Maple Math]

> for i from 1 to 7 do
> xn:=evalf(xn-f(xn)/df(xn));
> od;

[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]
[Maple Math]

Notice that the values keep getting farther from x=0. Here is a movie of this.
> newtonraphson(f(x),x=1);

[Maple Plot]

EXERCISES

Modify the code in this sheet to work on the exercises in this section in the text.

Dan Symancyk April 1994 October 1996 June 1997 March 1998 October 1998 March 1999

>