newton.m

来自「various matlab programs to slove various」· M 代码 · 共 12 行

M
12
字号
function [xvect,xdif,fx,nit]=newton(x0,nmax,toll,fun,dfun)err=toll+1; nit=0; xvect=x0; x=x0; fx=eval(fun); xdif=[];while (nit < nmax & err > toll),    nit=nit+1; x=xvect(nit); dfx=eval(dfun);    if (dfx == 0), err=toll*1.e-10;       disp(' Stop for vanishing dfun  ');    else,       xn=x-fx(nit)/dfx; err=abs(xn-x); xdif=[xdif; err];       x=xn; xvect=[xvect;x]; fx=[fx;eval(fun)];    end;end;

⌨️ 快捷键说明

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