function x=Minimize(f,a,b)
% MINIMIZE finds a minimum of a scalar function 
%   x=Minimize(f,a,b) searches for a minimum of the scalar function f
%   in the interval [a,b]

fa=f(a); fb=f(b);
l=(-1+sqrt(5))/2;
x1=l*a+(1-l)*b; x2=(1-l)*a+l*b;
fx1=f(x1); fx2=f(x2);
while a<x1 & x1<x2 & x2<b
  if fx1>fx2
    a=x1; 
    x1=x2; fx1=fx2; 
    x2=(1-l)*a+l*b; fx2=f(x2);
  else 
    b=x2; 
    x2=x1; fx2=fx1; 
    x1=l*a+(1-l)*b; fx1=f(x1);
  end;
end;
x=x1;
