Interval Line Search for Golden Selection

I know the algorithm but I don't know matlab enough, even to code this simple thing. So what I want to do is:
Let there be a function F and a start point xstart. I need to find an interval which includes the minimum of F by doing a line search. For the upper limit the algorithm is as follows:
let x(k+1)=x(k)+2^k
If F(x(k+1))>=F(x(k)), stop x(k+1)=b
else, repeat.
this also applies for the lower limit, the only changes are that you're not adding 2^k, you're subtracting it and that the inequality sign is different.
Can anyone help me out please, I know it's extremely simple but I've been stuck on this thing for 2 days now. The ultimate goal is to write a program to do Golden Selection method and minimize a function.

3 comentarios

I thought I got the interval search AND the golden selection, here's my code. Can someone tell me where I went wrong? The code gives the same answer for two different functions with two different minima.
clear all
clc
errx = 0.001;
errf = 0.001;
xstart = -25;
fn = 'hw1f'; % The function name
grc=double((sqrt(5)-1)/2); %golden rule constant
%-----------------------------------------------
%interval search start
i=1;
x(1)=xstart;
x(2)=x(1)+2;
while feval(fn,x(i))>feval(fn,x(i+1))
i=i+1;
x(i+1)=x(i)+2;
end
b=x(i+1);
i=1;
x(1)=xstart;
x(2)=x(1)-2;
while feval(fn,x(i))>feval(fn,x(i+1))
i=i+1;
x(i+1)=x(i)-2;
end
a=x(i+1);
%interval search end
%------------------------------------------------
%Golden Selection Start
i=1;
x1=a+grc*(b-a);
x2=b-grc*(b-a);
while abs(x1-x2)>errx && abs(feval(fn,x1)-feval(fn,x2))>errf %termination check
if feval(fn,x1)>=feval(fn,x2)
b=x1;
x1=x2;
x2=b-grc*(b-a);
else
a=x2;
x2=x1;
x1=a+grc*(b-a);
end
i=i+1;
end
xmin=x2
fmin=feval(fn,x2)
iter=i
Sarp Ulger
Sarp Ulger el 30 de Oct. de 2015
Ok, it started working, I have no idea why it didn't work the first time. I'll just leave this here just in case someone somewhere needs it.
Geoff Hayes
Geoff Hayes el 30 de Oct. de 2015
Sarp - what are the two functions that you are trying to minimize? Does the interval [a,b] make sense given where you think that the minimum should be? A cursory check of your algorithm seems correct but without knowing the functions that you are trying to minimize (or their inputs especially with respect to units) makes it difficult to know exactly what is wrong.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Productos

Preguntada:

el 29 de Oct. de 2015

Comentada:

el 30 de Oct. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by