Matlab编程问题:编写牛顿法程序来求解下面的方程组: (x-2)^2+(y-3+2x)^2=5 2(x-3)^2+(y/3)^2=4
1个回答
展开全部
% 用牛顿迭代法解非线性方程组
% F1=(x-2)^2+(y-3+2x)^2-5=0
% F2=2(x-3)^2+(y/3)^2-4=0
% F=[F1;F2]=[5*x^2 + 4*x*y - 16*x + y^2 - 6*y + 8
% 2*x^2 - 12*x + y^2/9 +14 ]
%迭代初值设为:X0=[x,y]=[0,0]'
% X(k+1)=X(k)+delt_X
% Jaco_F(X(k))*delt_X(k)=-F(X(k))
% Jaco_F为Jacobian矩阵
% Jaco_F=[10*x+4*y-16 2*y+4*x-6
% 4*x-12 2*y/9]
%error 为 ||X(k+1)-X(k)||,当error小于0.0001时,迭代停止
x=0;
y=0;
error=10;
while(error>0.0001)
F = [ 5*x^2+4*x*y-16*x+y^2-6*y+8
2*x^2-12*x+y^2/9+14 ];
Jaco_F = [10*x+4*y-16 2*y+4*x-6
4*x-12 2*y/9];
X = [x y]' - (inv(Jaco_F))*F; %迭代后的X值
error=norm(X-[x,y]'); % error=||X(k+1)-X(k)||
x=X(1);
y=X(2);
end
x
y
%%%%%%%%%%%%%到此结束%%%%%%%%%%%%%
程序结果:
x =
1.7362
y =
-2.6929
望采纳!
% F1=(x-2)^2+(y-3+2x)^2-5=0
% F2=2(x-3)^2+(y/3)^2-4=0
% F=[F1;F2]=[5*x^2 + 4*x*y - 16*x + y^2 - 6*y + 8
% 2*x^2 - 12*x + y^2/9 +14 ]
%迭代初值设为:X0=[x,y]=[0,0]'
% X(k+1)=X(k)+delt_X
% Jaco_F(X(k))*delt_X(k)=-F(X(k))
% Jaco_F为Jacobian矩阵
% Jaco_F=[10*x+4*y-16 2*y+4*x-6
% 4*x-12 2*y/9]
%error 为 ||X(k+1)-X(k)||,当error小于0.0001时,迭代停止
x=0;
y=0;
error=10;
while(error>0.0001)
F = [ 5*x^2+4*x*y-16*x+y^2-6*y+8
2*x^2-12*x+y^2/9+14 ];
Jaco_F = [10*x+4*y-16 2*y+4*x-6
4*x-12 2*y/9];
X = [x y]' - (inv(Jaco_F))*F; %迭代后的X值
error=norm(X-[x,y]'); % error=||X(k+1)-X(k)||
x=X(1);
y=X(2);
end
x
y
%%%%%%%%%%%%%到此结束%%%%%%%%%%%%%
程序结果:
x =
1.7362
y =
-2.6929
望采纳!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询