資源描述:
《牛頓法求解非線性方程組matlab源程序》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
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為相應(yīng)的Jacobian矩陣%tolp為P的允許誤差%tolfp為f(P)的允許誤差%max:循環(huán)次數(shù)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為相應(yīng)的Jacobian矩陣%tolp為P的允許誤差%tolfp為f(P)的允許誤差%max:循環(huán)次數(shù)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