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

📄 newtoniterate.m

📁 数值计算牛顿迭代法的matlab源程序 说明如下: %fun----input,the part as the form of f(x) in the equation f(x)=0 % ini
💻 M
字号:
function sol=Newtoniterate(fun,ini,err) 
%  File name:Newtoniterate.m      
%  Author:Yan Anxin
%  ID number:081810
%  Date:finished on 2008.10.27
%  Description:  
%    Here defines a function,to solve equation by newton's method.  
%       In the syntax sol=Newtoniterate(fun,ini,err),
%       fun----input,the part as the form of f(x) in the equation f(x)=0
%       ini----input,sets the starting point to ini 
%       err----input,sets admissible error
%       sol----output,returns the root of equation

df=diff(fun,'x');   %take a differential operation for the given function
k=2;
x(k-1)=ini;         %sets the initialization 
x(k)=x(k-1)-subs(fun,'x',x(k-1))/subs(df,'x',x(k-1));  %first operation
while abs(x(k)-x(k-1))>err            %Newton iteration
      x(k+1)=x(k)-subs(fun,'x',x(k))/subs(df,'x',x(k));
      k=k+1;
      if k>9999,fprinf('divergent iteration!'),break,end  %no convergence
end
sol=x(k);

⌨️ 快捷键说明

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