not obtaining a correct answer
显示 更早的评论
Hello, for some reason this golden section method to find the optimization guess, isnt giving the correct answer, its only doing two iteration and I can't figure out why.
function [xopt] = Sanchez_Gold1(xlow,xhigh,err)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
f=@(x)-1.5*x^6-2*x^4+12*x
N=1000
for i=1:N
xl=xlow;
xu=xhigh;
d=.5*(sqrt(5)-1)*(xu-xl);
x1=xl+d;
x2=xu-d;
if f(xl)>f(x2)
x1=x2;
else
xu=x1;
end
j=i+1;
xx(j)=x1; jj=j-1;
Err=abs(xx(j) - xx(j-1)); if Err < err, break;end
end
FF=f(x1);
disp(['optimal x= ' num2str(x1)])
2 个评论
Stephen23
2019-3-25
@Anthony Ming: please give us the exact input values that you are using.
Walter Roberson
2019-3-25
Every iteration for i, you overwrite xl and xu with the initial xlow and xhigh.
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!