资源描述:
《牛顿法求解非线性方程组matlab源程序》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、牛顿法求解非线性方程组matlab源程序Newton-Raphson求解非线性方程组matlab源程序matlab程序如下:function hom[P,iter,err]=newton('f','JF',[7.8e-001;4.9e-001;3.7e-001],0.01,0.001,1000);disp(P);disp(iter);disp(err); functionY=f(x,y,z)Y=[x^2+y^2+z^2-1; 2*x^2+y^2-4*z; 3*x^2-4*y+z^2]; functiony=JF(x,y,z)f1=
2、'x^2+y^2+z^2-1';f2='2*x^2+y^2-4*z';f3='3*x^2-4*y+z^2';df1x=diff(sym(f1),'x');df1y=diff(sym(f1),'y');df1z=diff(sym(f1),'z');df2x=diff(sym(f2),'x');df2y=diff(sym(f2),'y');df2z=diff(sym(f2),'z');df3x=diff(sym(f3),'x');df3y=diff(sym(f3),'y');df3z=diff(sym(f3),'z');j=[df1x,df1y,df1
3、z;df2x,df2y,df2z;df3x,df3y,df3z];y=(j); function[P,iter,err]=newton(F,JF,P,tolp,tolfp,max)%输入P为初始猜测值,输出P则为近似解%JF为相应的Jacobian矩阵%tolp为P的允许误差%tolfp为f(P)的允许误差%max:循环次数Y=f(F,P(1),P(2),P(3));fork=1:max J=f(JF,P(1),P(2),P(3)); Q=P-inv(J)*Y; Z=f(F,Q(1),Q(2),Q(3)); err=norm
4、(Q-P); P=Q; Y=Z; iter=k; if(err5、
6、(abs(Y)7、
8、abs(Y)<0.0001) break endend function homework4[P,iter,err]=newton('f','JF',[7.8e-001;4.9e-001;3.7e-001],0.01,0.001,1000);disp(P);disp(iter);disp(err); func
9、tionY=f(x,y,z)Y=[x^2+y^2+z^2-1; 2*x^2+y^2-4*z; 3*x^2-4*y+z^2]; functiony=JF(x,y,z)f1='x^2+y^2+z^2-1';f2='2*x^2+y^2-4*z';f3='3*x^2-4*y+z^2';df1x=diff(sym(f1),'x');df1y=diff(sym(f1),'y');df1z=diff(sym(f1),'z');df2x=diff(sym(f2),'x');df2y=diff(sym(f2),'y');df2z=diff(sym(f2
10、),'z');df3x=diff(sym(f3),'x');df3y=diff(sym(f3),'y');df3z=diff(sym(f3),'z');j=[df1x,df1y,df1z;df2x,df2y,df2z;df3x,df3y,df3z];y=(j); function[P,iter,err]=newton(F,JF,P,tolp,tolfp,max)%输入P为初始猜测值,输出P则为近似解%JF为相应的Jacobian矩阵%tolp为P的允许误差%tolfp为f(P)的允许误差%max:循环次数Y=f(F,P(1),P(2),P(3));
11、fork=1:max J=f(JF,P(1),P(2),P(3)); Q=P-inv(J)*Y; Z=f(F,Q(1),Q(2),Q(3)); err=norm(Q-P); P=Q; Y=Z; iter=k; if(err12、
13、(abs(Y)14、
15、abs(Y)<0.0001) break end