USING newton method optimization (getting error in 'xx(1)=x') .

조회 수: 2 (최근 30일)
RAHUL KUMAR
RAHUL KUMAR 2019년 8월 1일
답변: Bobby Huxford 2019년 8월 1일
rho_ss=8000;
rho_cop=8960;
x=[.001;.0014;.005;.007;.3];
D_i=x(1);D_io=x(2);D_o=x(3);D_oo=x(4);L=x(5);
wi=rho_ss*pi*D_io*(D_io-D_i)*L
wo=rho_cop*pi*D_o*(D_oo-D_o)*L
f=@(x) ((wi+wo)-.050)^2
fd=str2sym('((wi+wo)-.050)^2')
%f1=diff(fd,1)
%f2=diff(fd,2)
f1=@(x) (2.0*wi + 2.0*wo - 0.1)
f2=@(x) (2)
N=100; %no of iteration
err=.01; %result accuracy
xx(1)=x;
for i=1:N
x(i)=x-(f1(x)/f2(x));
j=i+1;
xx(j)=x;
Err=abs(xx(j))-abs(xx(j-1));
if Err<err,break;end
end

답변 (1개)

Bobby Huxford
Bobby Huxford 2019년 8월 1일
It would be easier to answer this if you wrote a question along with the code...
But the line xx(1)=x; will give you an error because you are trying to assign the 5 values in x to the first space in xx.
The line of code you may be looking for is:
However I am not sure what it is you are trying to do, so this could be wrong.
xx = x(1);

카테고리

Help CenterFile Exchange에서 Get Started with Optimization Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by