/// OPTIMİZASYON
//  ÖDEV 1
import java.io.*;


public class OPO1_V1
{

public static double f(double c)
{
 return -(2.0*c/(4.0+0.8*c+c*c+0.2*c*c*c));
}
	
public static double golden(double a,double b,double epsilon)
{return golden(a,b,epsilon,1.0e-10,0);}
public static double golden(double a,double b)
{return golden(a,b,1.0e-10,1.0e-10,0);}
public static double golden(double a,double b,double epsilon,double delta,int print)
{
//  f abstract function of class f_x (f(x) type of single function single variable)
//  fibonacchi golden ratio search
    double r1 = (Math.sqrt(5.0)-1.0)/2.0; // golden ratio
    double r2 = r1*r1;
    double h = b - a;
    double ya = f(a);
    double yb = f(b);
    double c = a + r2*h;
    double d = a + r1*h;
    double yc = f(c);
    double yd = f(d);
    int k = 1;
    double dp,dy,p,yp;
    while ((Math.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 = f(c);
        }
      else
       {
         a = c;
         ya = yc;
         c = d;
         yc = yd;
         h = b - a;
         d = a + r1 * h;
         yd = f(d);
       }//end of if
    }//end of while
    dp = Math.abs(b-a);
    dy = Math.abs(yb-ya);
    p = a;
    yp = ya;
    if (yb<ya)
    {
      p = b;
      yp = yb;
    }
    if(print==1)
    {System.out.println("x min = "+p+"ymin = "+yp+"error of x ="+dp+"error of y"+dy); }
    return p;
}

     public static void main (String args[])  
     { 
     double a=0,b=0;
     BufferedReader cin=new BufferedReader(new InputStreamReader(System.in));
     try 
     {
     System.out.print(" Fonksiyonun alt sinirini giriniz a : ");
     a=Double.parseDouble(cin.readLine());
     System.out.print(" Fonksiyonun alt sinirini giriniz a : ");
     b=Double.parseDouble(cin.readLine());
     } catch(IOException e2)  {System.err.println("Hatali sayi girisi");}
     double r;
     r= golden(a,b,1.0e-10);
     System.out.println(" optimizasyon degeri  : "+r+"\nFonksiyon degeri : "+f(r));
     } 
}