tianya7071 发表于 2007-11-15 16:37

求牛顿-拉夫逊法matlab代码?

求牛顿-拉夫逊法matlab代码?
谢谢!

风花雪月 发表于 2007-12-2 10:46

function =newdim(F,JF,P,delta,epsilon,max1)
%Input   -F is the system saved as the M-file F.m
%      -JF is the Jacobian of F saved as the M-file JF.m
%      -P is the initial approximation to the solution
%      -delta is the tolerance for P
%      -epsilon is the tolerance for F(P)
%      -max1 is the maximum number of iterations
% Output -P is the approximation to the solution
%      -iter is the number of iterations required
%      -err is the error estimate of P
Y=feval(F,P);
for k=1:max1
    J=feval(JF,P);
    Q=P-(J\Y')';
    Z=feval(F,Q);
    err=norm(Q-P);
    relerr=err/(norm(Q)+eps);
    P=Q;
    Y=Z;
    iter=k;
    if (err<delta)|(relerr<delta)|(abs(Y)<epsilon)
      break;
    end
end

茹果刘儿 发表于 2013-5-11 10:50

好东西~学习了~
页: [1]
查看完整版本: 求牛顿-拉夫逊法matlab代码?