** Next:** Exercises
**Up:** Newton's Method
** Previous:** Purpose

The need to solve nonlinear equations that cannot be solved analytically has led to the development of numerical methods. One of the most commonly used numerical methods is called Newton's method or the Newton-Raphson method. The idea of Newton's method is relatively simple. Suppose you have a nonlinear equation of the form

*f*(*x*) = 0

*y* = *f*(*x _{0}*)+

For example, consider the equation from above,

If you want to solve this equation using Newton's method, the first thing to do is to write it in standard form as Then, plot the expression to get an idea of where the roots are. You may have to adjust the plot range to locate all of the roots. The following commands show that there are exactly three roots, one at> f := x -> sin(x)-x/2;

> plot(f(x),x=-6..6);

It isn't very hard to write a Maple command that will do one step of
Newton's method. The examples below show a very simple method for
doing so, using the function *f* defined above and a starting value of
*x*=2.2.

> newt := x -> x-f(x)/D(f)(x);

> newt(2.2);

More steps can be obtained by using composition, as shown below. One can even get a little fancier by using the Maple

> newt(newt(2.2));

> (newt@@3)(2.2);

> seq((newt@@i)(2.2),i=1..4);

However, to simplify things for you, two commands,

> with(CalcP):

> Newton(f,x=2.2,3);

The

> NewtonPlot(f,x=2.2);

One of the problems with Newton's method is knowing when to stop. With a
numerical method, you can never get a root exactly, but only a
numerical approximation to the root. There are basically two measures
of how good your approximation to the root is. One is the absolute value of
*f*(*x*_{n}). If this number is less than a certain tolerance, then you
should have a good approximation to the root. The other measure is the
change in the value of *x*_{n}. If the value of *x*_{n} and *x*_{n+1} are
very close, then this can also be a criterion for stopping. You should
go back to the example above and experiment with changing the number
of iterations.

The worst thing about Newton's method is that it may fail to converge. Here is an example that doesn't seem to be converging after five iterations. Try increasing the number of iterations and see what happens.

> g := x -> x^5-12*x^4+3*x^3+7*x^2-2*x-1;

> plot(g(x),x=-2..2,y=-10..10);

> Newton(g,x=0,5);

The key to getting Newton's method to converge is to select a good starting value. The best way to do this is to plot the function and determine approximately where the roots are. The use these values to start Newton's method. For example, the following commands help locate a root of

> plot(g(x),x=-2..2,y=-10..10);

> Newton(g,x=-0.6,5);

12/2/1997