Page 192 - Applied Numerical Methods Using MATLAB
P. 192
ITERATIVE METHOD TOWARD FIXED POINT 181
satisfied around the solution point if we don’t have any rough estimate of the
solution.
function [x,err,xx] = fixpt(g,x0,TolX,MaxIter)
% solve x = g(x) starting from x0 by fixed-point iteration.
%input : g,x0 = the function and the initial guess
% TolX = upperbound of incremental difference |x(n + 1) - x(n)|
% MaxIter = maximum # of iterations
%output: x = point which the algorithm has reached
% err = last value |x(k) - x(k - 1)| achieved
% xx = history of x
if nargin < 4, MaxIter = 100; end
if nargin < 3, TolX = 1e-6; end
xx(1) = x0;
for k = 2:MaxIter
xx(k) = feval(g,xx(k - 1)); %Eq.(4.1.3)
err = abs(xx(k) - xx(k - 1)); if err < TolX, break; end
end
x = xx(k);
if k == MaxIter
fprintf(’Do not rely on me, though best in %d iterations\n’,MaxIter)
end
Example 4.1. Fixed-Point Iteration. Consider the problem of solving the nonlin-
ear equation
2
f 41 (x) = x − 2 = 0 (E4.1.1)
In order to apply the fixed-point iteration for solving this equation, we need
to convert it into a form like (4.1.4). Let’s try with the following three forms and
guess that the solution is in the interval I = (1, 1.5).
2
2
(a) How about x − 2 = 0 → x = 2 → x = 2/x = g a (x)? (E4.1.2)
Let’s see if the absolute value of the first derivative of g a (x) is less than
2
one for the solution interval, that is, |g a (x)|= 2/x < 1 ∀ x ∈ I.This
condition does not seem to be satisfied and so we must be pessimistic
about the possibility of reaching the solution with (E4.1.2). We don’t need
many iterations to confirm this.
2 2 2 2
x 0 = 1; x 1 = = 2; x 2 = = 1; x 3 = = 2; x 4 = = 1; ···
x 0 x 1 x 2 x 3
(E4.1.3)
The iteration turned out to be swaying between 1 and 2, never approaching
the solution.
2 2 1 2
(b) How about x − 2 = 0 → (x − 1) + 2x − 3 = 0 → x =− {(x − 1) −
2
3}= g b (x)? (E4.1.4)
This form seems to satisfy the convergence condition
|g b (x)|= |x − 1|≤ 0.5 < 1 ∀ x ∈ I (E4.1.5)