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
Stephen23 2019 年 3 月 25 日
@Anthony Ming: please give us the exact input values that you are using.
Walter Roberson
Walter Roberson 2019 年 3 月 25 日
Every iteration for i, you overwrite xl and xu with the initial xlow and xhigh.

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMATLAB についてさらに検索

タグ

質問済み:

2019 年 3 月 25 日

コメント済み:

2019 年 3 月 25 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by