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

2 次查看(过去 30 天)
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