📄 fixed_point.m
字号:
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
i = 1;
p(1) = p0;
tol = 1e-06;
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 = 5/x^2+2;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -