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

1 回表示 (過去 30 日間)
RAHUL KUMAR
RAHUL KUMAR 2019 年 8 月 6 日
編集済み: KALYAN ACHARJYA 2019 年 8 月 6 日
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
  2 件のコメント
madhan ravi
madhan ravi 2019 年 8 月 6 日
You try to stuff a vector as a scalar.
Walter Roberson
Walter Roberson 2019 年 8 月 6 日
Perhaps
err(i) = sum(abs(Y-Yold));
but more common would be
err(i) = sum((Y-Yold).^2);

サインインしてコメントする。

採用された回答

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 Center および File ExchangeInterpolation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by