Clear Filters
Clear Filters

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

1 view (last 30 days)
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

Accepted Answer

KALYAN ACHARJYA
KALYAN ACHARJYA on 6 Aug 2019
Edited: KALYAN ACHARJYA on 6 Aug 2019
>> 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.

More Answers (0)

Categories

Find more on Interpolation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!