Professional Documents
Culture Documents
(x
0
)(x x
0
) +
f
(z)
2
(x x
0
)
2
.
We can use l(x) f(x
0
) +f
(x
0
)(xx
0
) as an approximation to f(x). In order to solve
f(x) = 0, we solve l(x) = 0, which gives the solution
x
1
= x
0
f(x
0
)/f
(x
0
).
So x
1
can be regarded as an approximate root of f(x) = 0. If this x
1
is not a good
approximate root, we continue this iteration. In general we have the Newton iteration:
x
n+1
= x
n
f(x
n
)/f
(x
n
), n = 0, 1, . . . .
Here we assume f(x) is dierentiable and f
(x
n
) = 0.
Understand Newtons Method Geometrically
L
f
f(x)
T
x
new
x
5
The line L is tangent to f at (x, f(x)), and so has slope f
(x).
The slope of the line L is f(x)/(x x
new
), so:
f
(x) =
f(x)
x x
new
,
and consequently
x
new
= x
f(x)
f
(x)
.
This is just the Newton iteration.
Newtons Method Algorithm
Stopping criteria
|x
n+1
x
n
| xtol, or
|f(x
n+1
)| ftol, or
The maximum number of iteration reached.
Algorithm. Given f, f
(x)
x x d
if |d| xtol or |f(x)| ftol, then
root x
stop
end
end
root x
6
Newtons Method Matlab Code
function root=newton(fname,fdname,x,xtol,ftol,n_max,display)
% Newtons method.
%
%input:
% fname string that names the function f(x).
% fdname string that names the derivative f(x).
% x the initial point
% xtol and ftol termination tolerances
% n_max the maximum number of iteration
% display = 1 if step-by-step display is desired,
% = 0 otherwise
%output: root is the computed root of f(x)=0
%
n = 0;
fx = feval(fname,x);
if display,
disp( n x f(x))
disp(-------------------------------------)
disp(sprintf(%4d %23.15e %23.15e, n, x, fx))
end
if abs(fx) <= xtol
root = x;
return
end
for n = 1:n_max
fdx = feval(fdname,x);
d = fx/fdx;
x = x - d;
fx = feval(fname,x);
if display,
disp(sprintf(%4d %23.15e %23.15e,n,x,fx))
end
if abs(d) <= xtol | abs(fx) <= ftol
root = x;
return
end
end
The function f(x) and its derivative f
(x
n
) = 0 the method is not dened.
If f
(x
n
) 0 then there may be diculties. The new estimate x
n+1
may be a
much worse approximation to the solution than x
n
is.
8
Convergence Analysis of Newtons Method
Def. Quadratic convergence (QC).
A sequence {x
n
} is said to have QC to a limit x if
lim
n
|x
n+1
x|
|x
n
x|
2
= c,
where c is some nite non-zero constant.
Newton iteration:
x
n+1
= x
n
f(x
n
)/f
(x
n
).
Suppose x
n
converges to a root r of f(x) = 0.
Taylor series expansion about x
n
is
f(r) = f(x
n
) + (r x
n
)f
(x
n
) +
(r x
n
)
2
2
f
(z
n
)
where z
n
lies between x
n
and r.
But f(r) = 0, and dividing by f
(x
n
)
0 =
f(x
n
)
f
(x
n
)
+ (r x
n
) + (r x
n
)
2
f
(z
n
)
2f
(x
n
)
.
The 1st term on the RHS is x
n
x
n+1
, so
r x
n+1
= c
n
(r x
n
)
2
, c
n
f
(z
n
)
2f
(x
n
)
.
Writing the error e
n
= r x
n
, we see
e
n+1
= c
n
(e
n
)
2
.
Since x
n
r, and z
n
is between x
n
and r, we see z
n
r and so
lim
n
|e
n+1
|
|e
n
|
2
= lim
n
|c
n
| =
|f
(r)|
|2f
(r)|
c
assuming that f
(r) = 0.
So the convergence rate of Newton method is usually quadratical. At the (n + 1)-th
step, the new error is equal to c
n
times the square of the old error.
Also we can show f(x
n
) usually converges to 0 quadratically:
Q. Under which condition, x
n
r?
It can be shown that if f
(r) = 0 but f
(r) = 0, then
lim
n
|e
n+1
/e
2
n
| = 0.
NM converges faster than quadratic convergence.
e.g., f(x) = sin(x), r = .
Try newton(f,fd,4,1.e-12,1.e-12,20,1)
If f
(x
n
).
Problem with Newtons method: it requires software for the derivative f
(x) in
many instances, dicult or impossible to encode.
Q: How to get around the problem?
Use divided dierence
f(xn)f(x
n1
)
xnx
n1
to replace f
(x
n
), we get the secant iteration:
x
n+1
= x
n
x
n
x
n1
f(x
n
) f(x
n1
)
f(x
n
).
This formula can be understood geometrically:
Draw a secant line which connects two points (x
n1
, f(x
n1
)) and (x
n
, f(x
n
)) on the
graph of y = f(x). The cross point of the secant line and the x-axis is exactly the x
n+1
dened by the secant iteration formula.
10
Algorithm. Given f, x
0
, x
1
(two initial points), xtol, ftol, n
max
for n = 1 : n
max
d
x
1
x
0
fx
1
fx
0
fx
1
x
0
x
1
fx
0
fx
1
x
1
x
1
d
fx
1
f(x
1
)
if |d| xtol or |fx
1
| ftol, then
root x
1
return
end
end
root x
1
11
Convergence of the Secant Method
If x
n
converges to a root r of f(x) = 0, we can show (somewhat dicult) that
lim
k
|x
n+1
r|
|x
n
r|
p
= c
where p = (1 +
.
Disadvantages: slower than NM, may not converge.
Two MATLAB Commands
There are two Matlab built-in functions:
roots for nding all roots of a polynomial.
fzero for nding a root of a general function.
Check Matlab to see how to use these two functions.
12