newton.m

来自「a m file for matlab the secant method」· M 代码 · 共 26 行

M
26
字号
function rtn=newton(fx,dfx,x0,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);df0=eval(dfx);
n=0;


   while n<=N
      x1=x0-f0/df0;
      x=x1;f1=eval(fx);df1=eval(fx)
      X=[n,x0,x1,f1];
      disp(X);
      if abs(x1-x0)<tol
          fprintf('The procedure was successful.')
          return
      else
          n=n+1; x0=x1;f0=f1;
      end
   end

  if n==N+1
    fprintf('the method failed after N iterations. ')
 end

⌨️ 快捷键说明

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