用牛顿迭代法求解非线性方程组
主程序newton.m
clear
clc
[F,v]=wuzu;
x1=input('请输入初值:');
eps=input('请输入误差精度:');
b=jacobian(F,v);
for i=1:1:length(x1)
b=subs(b,v(i),x1(i));
F=subs(F,v(i),x1(i));
end
b=eval(b);
F=eval(F);
x2=x1-b\F';
i=1;
while max(abs(x2-x1))>=eps
x1=x2;
F=wuzu;
b=jacobian(F,v);
for i=1:1:length(x1)
b=subs(b,v(i),x1(i));
F=subs(F,v(i),x1(i));
end
b=eval(b);
F=eval(F);
x2=x1-b\F';
i=i+1;
if i==1000
break;
end
end
if i>=1000
disp('newton迭代法很可能不收敛!')
else
disp('方程的根是:');
x=x2
end
所要求解非线性方程组 wuzu,m
function [F,v]=wuzu
syms x y
f1=atan(x^(1/3)+y^(2/3)-4)-1;
f2=exp(x^(-2)+y^(-2))-4;
F=[f1,f2];
v=[x,y];
end
结果展示: