⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 secant.m

📁 a m file for matlab the secant method
💻 M
字号:
function secant(fx,x0,x1,tol,N)
% Secant Method
% 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.
x=x0;f0=eval(fx);
x=x1;f1=eval(fx);
n=0;
if f0<f1    
    a=x0; x0=x1; x1=a;
    b=f0; f0=f1; f1=b;
end
while n<=N
    x2=x1-f1*(x0-x1)/(f0-f1);
    x=x2;f2=eval(fx);
    X=[n,x0,x1,x2,f2];
    disp(X);
    if abs(x2-x1)<tol
        fprintf('The procedure was successful.')
        return
    else  
        n=n+1;
        x0=x1;f0=f1;x1=x2;f1=f2;
    end
end
if n==N+1
    fprintf('the method failed after N iterations. '),
 end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -