function p = goldenSpline(S,a,b)
r1=(sqrt(5)-1)/2;
r2=1-r1;
h=b-a;
ya=funcSpline(S,a);
yb=funcSpline(S,b);
c=a+r2*h;
d=a+r1*h;
yc=funcSpline(S,c);
yd=funcSpline(S,d);
k=1;
epsilon=1.0e-8;
delta=1.0e-8;
while (abs(yb-ya) > epsilon & (h>delta))
   k++;
   if yc<yd 
       b = d;
        yb = yd;
        d = c;
        yd = yc;
        h = b - a;
        c = a + r2 * h;
        yc =funcSpline(S,c);
    else    
         a = c;
         ya = yc;
         c = d;
         yc = yd;
         h = b - a;
         d = a + r1 * h;
         yd =funcSpline(S,d);
    endif     
endwhile
p=a;
yp=ya;
if yb<ya 
   p=b;
   yp=yb;
endif  
endfunction

