not obtaining a correct answer
Ältere Kommentare anzeigen
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 Kommentare
Stephen23
am 25 Mär. 2019
@Anthony Ming: please give us the exact input values that you are using.
Walter Roberson
am 25 Mär. 2019
Every iteration for i, you overwrite xl and xu with the initial xlow and xhigh.
Antworten (0)
Kategorien
Mehr zu MATLAB finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!