The Fixed-point iteration algorithm in Matlab :
function fixed_point(p0, N)
%Fixed_Point(p0, N) approximates the root of the equation f(x) = 0
%rewritten in the form x = g(x), starting with an initial approximation p0.
%The iterative technique is implemented N times.
%The user has to enter the function g(x)at the bottom
%Author: Alain G. Kapitho
%Date : Jan. 2006
i = 1;
p(1) = p0;
tol = 1e-05;
while i <= N
p(i+1) = g(p(i));
if abs(p(i+1)-p(i)) < tol %stopping criterion
disp('The procedure was successful after k iterations')
k = i
disp('The root to the equation is')
p(i+1)
return
end
i = i+1;
end
if abs(p(i)-p(i-1)) > tol | i > N
disp('The procedure was unsuccessful')
disp('Condition |p(i+1)-p(i)| < tol was not sastified')
tol
disp('Please, examine the sequence of iterates')
p = p'
disp('In case you observe convergence, then increase the maximum number of iterations')
disp('In case of divergence, try another initial approximation p0 or rewrite g(x)')
disp('in such a way that |g''(x)|< 1 near the root')
end
%this part has to be changed accordingly with the specific function g(x)
function y = g(x)
%y = x - x.^3 - 4*x.^2 + 10;
%y = sqrt(10./x - 4*x);
y = x - (x.^3 + 4*x.^2 - 10)/(3*x.^2 + 8*x);
|
No comments:
Post a Comment