设为首页收藏本站

EPS数据狗论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1429|回复: 0

牛顿迭代法解非线性方程程序

[复制链接]

13

主题

152

金钱

235

积分

入门用户

发表于 2018-9-20 14:51:29 | 显示全部楼层 |阅读模式
  1. function x=newton(f_name,x0,tol)
  2. % Purpose: Solve a nonlinear equation by Newton iteration
  3. % Synopsis:     x=newton('f_name',x0)      
  4. %               x=newton('f_name',x0,tol)  
  5. %
  6. %            x: return a root of f(x)=0 near x0
  7. %            f_name:name of the function f(x) that defines the equation
  8. %            x0: initial guess
  9. %            tol: tolerence(Default:1e-6)

  10. % L.J.Hu 1-8-1998

  11. h=0.0001;M=500;
  12. if nargin<3, tol=1e-6;end
  13. x=x0;xb=x-999;
  14. n=0;
  15. while abs(x-xb)>tol
  16.   xb=x;
  17.   if n>M break;end
  18.   y=feval(f_name, x);
  19.   fprintf('  n=%3.0f,  x=%12.5e,  y=%12.5e, \n',n,x,y)
  20.   y_driv=(feval(f_name,x+h)-y)/h;
  21.   x=xb-y/y_driv;
  22.   n=n+1;
  23. end
  24. fprintf('  n=%3.0f,  x=%12.5e,  y=%12.5e, ',n,x,y)
  25. if n>500,
  26. fprintf('\n');disp('Warning: iterations exceeds the limitation, probable devergent');
  27. end
复制代码


NEWTON.rar

540 Bytes, 下载次数: 0, 下载积分: 贡献 -1

售价: 1 金钱  [记录]  [购买]

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

客服中心
关闭
在线时间:
周一~周五
8:30-17:30
QQ群:
653541906
联系电话:
010-85786021-8017
在线咨询
客服中心

意见反馈|网站地图|手机版|小黑屋|EPS数据狗论坛 ( 京ICP备09019565号-3 )   

Powered by BFIT! X3.4

© 2008-2028 BFIT Inc.

快速回复 返回顶部 返回列表