tengfeizhiyan 发表于 2008-5-10 10:05

关于牛顿法求解非线性方程组的问题

我只知道牛顿法求解非线性方程的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,,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');
= 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 optionsandxo

tengfeizhiyan 发表于 2008-5-10 21:22

谢谢!
可这个不是Newton迭代法解非线性方程组的MATLAB解法啊,我想知道的是Newton迭代法解非线性方程组,有谁知道啊?帮小妹一把........
页: [1]
查看完整版本: 关于牛顿法求解非线性方程组的问题