

f = inline('1./x + exp(sqrt(x))');
%f = inline('(x<.5).*(1.25 - 2*x)+ (x >=.5).*(x-.5).^2')
x = linspace(.5,1, 101);
plot(x, f(x))
N = 10;
a0 = .5 ; b0 = 1;
r = (sqrt(5)-1)/2;

alist = zeros(N,1);
blist = zeros(N,1);
a = a0; b = b0;
s = a + (1-r)*(b-a);
t = b - (1-r)*(b-a);
f1 = f(s);
f2 = f(t);
for n = 1:N
    
    if f1 < f2
        b = t;
        t = s;
        s = a+(1-r)*(b-a);
        f2 = f1; f1 = f(s);
    else
        a = s;
        s = t;
        t = b-(1-r)*(b-a);
        f1 = f2;
        f2 = f(t);
    end
    alist(n) = a;
    blist(n) = b;
end
disp('      a        b       f(a)       f(b)      b-a   ') 
disp(' ')
alist = [a0;alist];
    blist = [b0; blist];
    [alist, blist, f(alist), f(blist), blist-alist]
    
    

