Up to Main Lab Page | Next Lesson - Fixed Point Iteration | Previous Lesson - The Bisection Method |
The bisection method is useful only up to a point. In order to get good accuracy we must do a relatively large number of iterations. This is even more of a problem if many roots are to be found. A much better algorithm is Newton's method.
The idea of Newton's method is to make an initial guess, a0,
close to the root.
The point where the tangent line to f at a0 meets the
x axis is our next approximation, a1.
We then repeat as needed.
We can calculate the value of the n+1th step in this
process, an+1, from an,
f (an) and
f '(an).
The equation of the tangent at an is
y = f '(an)(x - an)
+ f (an).
Expanding gives
y = x f '(an)
- an f '(an)
+ f (an).
an+1 is the point where this line crosses the
x axis.
This happens when y = 0, solving y = 0 gives:
This is the formula for the next approximation in Newton's Method.
Repeat | |
a := a - f (a) / f '(a) | |
Return a |
Unfortunately this error bound is not much use for practical purposes.
A much more useful way of estimating the error is that it can be shown that the
difference between successive approximations is greater than the error.
Thus
En+1 < |an+1 -
an|
Note that |an+1 - an| =
|f (an) / f
'(an)|
Thus we may continue iterating until the difference between successive approximations, |an+1 - an|, is less than the required value.
We will need the derivative of f.
> g := D(f);
We need a first approximation for a0. We get this by
looking at a plot.
> plot(f(x), x = -Pi..Pi);
We once again see that the root is between 0 and 1, thus 0.5 would be a
reasonable assumption for a0.
> a := .5;
We will again set the error to 10-20, and ensure that the accuracy
is high enough.
> error := 10^(-20);
> Digits := 30;
We now implement the algorithm. We use the variable b to record the
error at each stage, we initially set this to 1.
> b := 1;
> while abs(evalf(b)) > error
> do
> b := f(a)/g(a);
> a := a - b;
> od:
We can now see the answer.
> a;
We can check that this agrees to the answer given by the Bisection method to
within 20 decimal places.
> evalf(a - 0.6417143708728826583998394901542372537051);
Why do we use the variable b?
Use your program to find the answer.
First if f '(x) = 0 near the root, then both the numerator and denominator in f (an) / f '(an) are near zero. This necessitates a computation of both f (an) and f '(an) to a high degree of accuracy.
Further we must be careful to avoid points for which f
'(an) = 0, since this will produce a divide by 0 error.
This is particularly important in our first guess.
In a similar vien we must avoid points where the derivative is undefined.
If any of our an are close to a turning point of f the tangent will be nearly flat and the intercept will be far away.
If our initial guess is on the other side of a turning point of f, where there is no root it is possible that the method will diverge, or at least converge very slowly.
As an example consider the following picture showing successive approximations
from an initial "bad" guess.
a0 is on the wrong side of the turning point, and so
a1 is further away from the root.
a2, a3 and a4
are once again moving closer to the root.
Though a4 is on the right side of the turning point it is
close to the turning point and so the tangent is nearly flat, thus the intercept
will be far away from the root.
Finally there is a possibility that the algorithm does not converge at all, but
bounces between two values.
To see this consider the picture below.
The tangent to a1 hits the axis at
a0, thus a2 =
a0
Continuing, the tangent of a2 is the same as the tangent
to a0, and so a3 =
a1.
In general
an = | a0 | If n is even |
a1 | If n is odd |
Thus the iteration jumps forever between these two values and never converges
to the root.
Try using a = 1.5 to an accuracy of 10-20.
How many iterations did it take? Why so many?
Clearly f(x) has a root at x = 4.
f(x) =
-sqrt(4 - x)
If x < 4
sqrt(x - 4)
If x >= 4
Note, you may find the STOP button on the tool bar useful at this point.
You also may want to issue a restart to clear the memory.
Try some other points.
Can you now explain this behaviour?
Up to Main Lab Page | Next Lesson - Fixed Point Iteration | Previous Lesson - The Bisection Method | Top of this Lesson |