필터 지우기
필터 지우기

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
  댓글 수: 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 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