USING newton method optimization (getting error in 'xx(1)=x') .
2 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Bobby Huxford
on 1 Aug 2019
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);
0 Comments
See Also
Categories
Find more on Get Started with Optimization Toolbox 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!