Golden Search Optimization Problem

Hello everyone! I've been trying to figure out how to code the Golden Search algorithm for the function G with an initial interval of [-2,4]. However, I've been getting odd answers when I compared it with Newton's method. I was wondering if there was anything wrong with my code.
G = 4*x - (1.8*x^2) + (1.2*x^3) - (.3*x^4)
%Golden search method
%Define the parameters
phi = (1 + sqrt(5))/2;
a = -2;
b = 4;
n = 0;
c1 = (phi - 1)*a + (2-phi)*b;
c2 = (2-phi)*a + (phi - 1)*b;
G = @(x)(4*x - (1.8*x^2) + (1.2*x^3) - (.3*x^4));
g1 = G(c1);
g2 = G(c2);
while abs(b-a) > 0.0001
n = n+1;
if g1 < g2
b = c2;
c2 = c1;
g2 = g1;
c1 = (phi - 1)*a + (2 - phi)*b;
g1 = G(c1);
else
a = c1;
c1 = c2;
g1 = g2;
c2 = (2 - phi)*a + (phi - 1)*b;
f2 = G(c2);
end
end
for a comparison, I wrote a simple newton's method algorithm.
%Initial guess
x = 3;
%Desired tolerance and dummy tolerance to start iteration
Tol = 0.0001;
dummytol = 100;
while dummytol > Tol
X = x;
G = 4*x - (1.8*x^2) + (1.2*x^3) - (.3*x^4);
%Use derivative of the function to find the new volume
dG = 4 - 3.6*x + 3.6*x^2 - 1.2*x^3;
x = x - G/dG;
%Replace dummy tolerance with new tolerance
dummytol = abs(x - X);
end;
I got a maximum of 3.39 for newtons and -2 for the golden search. Thank you for any help!

3 件のコメント

SERGIO RODRIGUEZ
SERGIO RODRIGUEZ 2013 年 4 月 27 日
You implement a minimization problem with the golden search....The result its reasonable.
SERGIO RODRIGUEZ
SERGIO RODRIGUEZ 2013 年 4 月 27 日
And.. phi = (-1 + sqrt(5))/2;
Aric Acius
Aric Acius 2017 年 10 月 21 日
Might be 5 years late, but in your else statement you calculate f2 instead of g2.

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

回答 (0 件)

カテゴリ

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

質問済み:

2012 年 11 月 2 日

コメント済み:

2017 年 10 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by