fixed_point.m
来自「a m file for matlab the secant method」· M 代码 · 共 24 行
M
24 行
function rtn=fixed_point(fx,x0,tol,N)
% Fixed-Point Iteration
% The first parameter fx is a external function with respect to viable x.
% x0,x1 are initial iteration points.
% tol is the tolerance of the loop.
% N is the maximum number of iterations.
i=1;
while i<=N
x=x0;
f0=eval(fx);
x1=f0;
x=x1;f1=eval(fx);
X=[i,x0,x1,f1];
disp(X);
if abs(x1-x0)<tol
fprintf('The procedure was successful.')
return
else
i=i+1; x0=x1;f0=f1;
end
end
if i==N+1
fprintf('The method failed after N iterations. ')
end
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?