not obtaining a correct answer
Show older comments
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 Comments
Stephen23
on 25 Mar 2019
@Anthony Ming: please give us the exact input values that you are using.
Walter Roberson
on 25 Mar 2019
Every iteration for i, you overwrite xl and xu with the initial xlow and xhigh.
Answers (0)
Categories
Find more on MATLAB 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!