声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1045|回复: 3

[编程技巧] 关于牛顿法求解非线性方程组的问题

[复制链接]
发表于 2008-5-10 10:05 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
我只知道牛顿法求解非线性方程的MATLAB程序,但应用到非线性方程组就不行了
function x=nanewton(fname,dfname,x0,e,N)
if nargin<5,N=500;end
if nargin<4,e=1e-4;end
x=x0;x0=x+2*e;k=0;
while abs(x0-x)>e&k<N,
    k=k+1;
    x0=x;x=x0-feval(fname,x0)/feval(dfname,x0);
    disp(x)
end
if k==N,waring('已达迭代次数上限');end
在MATLAB命令窗口中输入:
》fun=inline('4*x1+4*x2;4*x1+4*x2+(x1-x2)*((x1-2)^2+x2^2-1)');
dfun=inline('4,4;3*x1^2+x2^2-2*x1*x2+4*x2-8*x1+7,2*x1*x2+4*x1-3*x2^2-x1^2+1')
》nanewton(fun,dfun,[2,2],0.5e-3)

各位帮帮忙,看我的程序错在哪,我对MATLAB不熟悉.......

[ 本帖最后由 eight 于 2008-5-12 18:48 编辑 ]
回复
分享到:

使用道具 举报

发表于 2008-5-10 18:13 | 显示全部楼层
we can use the function fminunc to solve such nonlinear equation,as following

function f = objfun(x)
f = 4*x(1)+4*x(2);4*x(1)+4*x(2)+(x(1)-x(2))*((x(1)-2)^2+x(2)^2-1);

>> x0 = [-1,1]; % Starting guess
options = optimset('LargeScale','off');
[x,fval,exitflag,output] = fminunc(@objfun,x0,options)

Optimization terminated: relative infinity-norm of gradient less than options.TolFun.

x =

  1.0e+014 *

   -8.1248   -8.1248


fval =

-6.4998e+015


exitflag =

     1


output =

       iterations: 2
        funcCount: 33
         stepsize: 1
    firstorderopt: 0
        algorithm: 'medium-scale: Quasi-Newton line search'
          message: 'Optimization terminated: relative infinity-norm of gradient less than options.TolFun.'
发表于 2008-5-10 18:23 | 显示全部楼层
sorry,there is a problem hereinbefore.
it's only for your information.
you shall reset the options  and  xo
 楼主| 发表于 2008-5-10 21:22 | 显示全部楼层
谢谢!
可这个不是Newton迭代法解非线性方程组的MATLAB解法啊,我想知道的是Newton迭代法解非线性方程组,有谁知道啊?帮小妹一把........
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-9-23 09:26 , Processed in 0.061340 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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