newton.m

来自「用matlab写的一些数值算法」· M 代码 · 共 15 行

M
15
字号
function [x,k] = newton(fdf,x0,tol,kmax)
% Solve f(x)=0 by Newton-Raphson's method.
% f(x) and f'(x) given by  [f,df] = fdf(x)
% Starting point x0.  
% Iterate until correction is smaller than tol 
% or the number of steps exceeds kmax

% Version 11.12.2003.  INCBOX

k = 0;   x = x0;  % initialize
[f, df] = feval(fdf, x);   h = f/df;
while  (abs(h) > tol) & (k < kmax)
  k = k+1;   x = x - h;
  [f, df] = feval(fdf, x);   h = f/df;
end

⌨️ 快捷键说明

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