请问你会用牛顿迭代法解这个问题么?
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/15 10:10:58
请问你会用牛顿迭代法解这个问题么?
请问你会用牛顿迭代法解这个问题么?
请问你会用牛顿迭代法解这个问题么?
但是牛顿法可能解不出来
function [r,n]=mulNewton(x0,eps)
if nargin==1
eps=1.0e-4;
end
r=x0-myf(x0)*inv(dmyf(x0));
n=1;
tol=1;
while tol>eps
x0=r;
r=x0-myf(x0)*inv(dmyf(x0));
tol=norm(r-x0);
n=n+1;
if(n>100000)
disp('迭代步数太多,方程可能不收');
return;
end
end
function f=myf(x)
x1=x(1);
x2=x(2);
f1=(15*x1+10*x2)/((40-30*x1-10*x2)^2*(15-15*x1))-5e-4;
f2=(15*x1+10*x2)/((40-30*x1-10*x2)*(10-10*x2))-4e-2;
f=[f1 f2];
function df=dmyf(x)
x1=x(1);
x2=x(2);
df=[ (60*(15*x1 + 10*x2))/((15*x1 - 15)*(30*x1 + 10*x2 - 40)^3) - 15/((15*x1 - 15)*(30*x1 + 10*x2 - 40)^2) + (15*(15*x1 + 10*x2))/((15*x1 - 15)^2*(30*x1 + 10*x2 - 40)^2),(20*(15*x1 + 10*x2))/((15*x1 - 15)*(30*x1 + 10*x2 - 40)^3) - 10/((15*x1 - 15)*(30*x1 + 10*x2 - 40)^2);...
15/((10*x2 - 10)*(30*x1 + 10*x2 - 40)) - (30*(15*x1 + 10*x2))/((10*x2 - 10)*(30*x1 + 10*x2 - 40)^2), 10/((10*x2 - 10)*(30*x1 + 10*x2 - 40)) - (10*(15*x1 + 10*x2))/((10*x2 - 10)*(30*x1 + 10*x2 - 40)^2) - (10*(15*x1 + 10*x2))/((10*x2 - 10)^2*(30*x1 + 10*x2 - 40))];
-----------------------------------------------
[r,n]=mulNewton([0.5 0.1],0.0001)
Warning: Matrix is close to singular or badly scaled.
Results may be inaccurate. RCOND = 1.148287e-034.
> In mulNewton at 10
Warning: Matrix is close to singular or badly scaled.
Results may be inaccurate. RCOND = 1.195848e-089.
> In mulNewton at 10
Warning: Matrix is close to singular or badly scaled.
Results may be inaccurate. RCOND = 5.295160e-267.
> In mulNewton at 10
Warning: Matrix is singular to working precision.
> In mulNewton at 10
Warning: Matrix is singular, close to singular or badly scaled.
Results may be inaccurate. RCOND = NaN.
> In mulNewton at 10
r =
NaN NaN
n =
9