Error in newton rapshon problem. My error in iteration line (err(i))=abs(Y-Yold)

1 次查看(过去 30 天)
X=[.0014;.0075;.3];
maxiter=100;
tolX=.000001;
Y=X;
Yold=X;
rho_ss=8000;
rho_cop=8960;
% defined thickness
thick_i=.0004;
thick_o=.00135;
D_i=X(1);D_o=X(2);L=X(3);
%% function value
fval=(((rho_ss*pi*thick_i*D_i*L)+(rho_cop*pi*thick_o*D_o*L))-.05).^2; % objective function
%% putting jacobian function
J=2*[((rho_ss*pi*D_i*thick_i*L+rho_cop*pi*D_o*thick_o*L)-.05)*(rho_ss*pi*thick_i*L);
((rho_ss*pi*D_i*thick_i*L+rho_cop*pi*D_o*thick_o*L)-.05)*(rho_cop*pi*thick_o*L);
((rho_ss*pi*D_i*thick_i*L+rho_cop*pi*D_o*thick_o*L)-.05)*(rho_ss*pi*thick_i+rho_cop*pi*thick_o)];
%% hessian function
H=[(rho_ss^2*pi^2*thick_i^2*L^2) (rho_cop*rho_ss*pi^2*thick_i*thick_o*L^2) ((2*rho_ss^2*pi^2*D_i*thick_i^2*L)+(2*rho_ss*rho_cop*pi^2*thick_i*thick_o*L)-(.05*rho_ss*pi*thick_i));
(rho_ss*rho_cop*pi.^2*thick_i*thick_o*L.^2) (rho_cop.^2*pi.^2*thick_o.^2*L.^2) ((rho_ss*rho_cop*pi.^2*D_i*thick_i*thick_o*L)+(rho_cop.^2*pi.^2*thick_o.^2*2*L)-(.05*rho_cop*pi*thick_o));
((rho_ss.^2*pi.^2*2*D_i*thick_i.^2*L)+(2*(rho_cop*rho_ss*pi.^2*D_o*thick_i*thick_o*L))-(.05*rho_ss*pi*thick_i)) (2*(rho_ss*rho_cop*pi.^2*D_i*thick_i*thick_o*L)+(rho_cop.^2*pi.^2*2*D_o*thick_o.^2*L-.05*rho_cop*pi*thick_o)) ((rho_ss.^2*pi.^2*D_i.^2*thick_i.^2)+(2*(rho_cop*rho_ss*pi.^2*D_i*D_o*thick_i*thick_o))+(rho_cop.^2*pi.^2*D_o.^2*thick_o))];
%% using optimization in newton rapshon
for i=1:maxiter
Y=Y - (J./H); % newton -rapshon
Yold=Y;
err(i)=abs(Y-Yold); % error iteration
if (err(i)<tolX)break;
end
end

采纳的回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2019-8-6
编辑:KALYAN ACHARJYA 2019-8-6
>> whos Y
Name Size Bytes Class Attributes
Y 3x3 72 double
>> whos Yold
Name Size Bytes Class Attributes
Yold 3x3 72 double
When I checked it-
Y =
-0.0249 -0.0056 0.0004
-0.0188 0.0005 0.0065
-2.6337 -0.4761 0.2366
And
Yold =
-0.0249 -0.0056 0.0004
-0.0188 0.0005 0.0065
-2.6337 -0.4761 0.2366
Now find the error(i)
>> abs(Y-Yold)
ans =
0 0 0
0 0 0
0 0 0
In each iteration the error (err) will be same because, you cpoying Y to Yold, abs(Y-Yold) becomes 0
Yold=Y;
err(i)=abs(Y-Yold);
Now you want to save 3x3 (Y-Yold) zero 2D vector (matrix) in an err array, which is not permissible.
May be (not Sure): As per my observation the err(i) should have numeric value. Please debug the code from back onwards, why the Y return as 3x3.
Hope you get the issue.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Nonlinear Optimization 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by