《牛顿法求解非线性方程组matlab源程序.doc》由会员分享,可在线阅读,更多相关《牛顿法求解非线性方程组matlab源程序.doc(4页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、【精品文档】如有侵权,请联系网站删除,仅供学习与交流牛顿法求解非线性方程组matlab源程序.精品文档.牛顿法求解非线性方程组matlab源程序Newton-Raphson 求解非线性方程组matlab源程序matlab程序如下:functionhomP,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);function Y=f(x,y,z)Y=x2+y2+z2-1;2*x2+y2-4*z;3*x2-4*y+z2;function y=JF(x,y,z)f
2、1=x2+y2+z2-1;f2=2*x2+y2-4*z;f3=3*x2-4*y+z2;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,df1z;df2x,df2y,df2z;df3x,df3y,df3z;y=(j);function P,iter
3、,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);for k=1:maxJ=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 (errtolp)|(abs(Y)tolfp|abs(Y)0.0001)breakendendfunctionhomework4P,iter,er
4、r=newton(f,JF,7.8e-001;4.9e-001; 3.7e-001,0.01,0.001,1000);disp(P);disp(iter);disp(err);function Y=f(x,y,z)Y=x2+y2+z2-1;2*x2+y2-4*z;3*x2-4*y+z2;function y=JF(x,y,z)f1=x2+y2+z2-1;f2=2*x2+y2-4*z;f3=3*x2-4*y+z2;df1x=diff(sym(f1),x);df1y=diff(sym(f1),y);df1z=diff(sym(f1),z);df2x=diff(sym(f2),x);df2y=dif
5、f(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,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);for k=1:maxJ=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 (errtolp)|(abs(Y)tolfp|abs(Y)0.0001)breakend