//***********************************************************************************
/** Class to return iterate of Bakers' map function.<br>
*/
//***********************************************************************************

public class BakersFunction extends Map2DFunction {
      double X,Y;

      BakersFunction() {      

            nParameters=3;    
            a = new double[nParameters];    
            aDefault = new double[nParameters];
            aDefault[0]=0.4;
            aDefault[1]=0.6;
            aDefault[2]=0.2;      
            title = "Bakers Map";
            xminDefault=0.0;
            xmaxDefault=1.0;
            yminDefault=0.0; 
            ymaxDefault=1.0;
      }      
                       
      
//***********************************************************************************      
/** iterates the map function
* @param x input value
* @return iterated value
*/
//***********************************************************************************
      public void iterate(double[] x) {                       

            X = x[0];
            Y = x[1];
           if (Y<a[0]){
                  x[0]=a[1]*X;
                  x[1]=Y/a[0];
           }
           else{  
                x[0]=(1-a[2])+a[2]*X;
                x[1]=(Y-a[0])/(1-a[0]);
           }
           
           x[2]=X;
           x[3]=Y;  
      }      

//***********************************************************************************      
/** iterates the tangent space to the map
* @param x input value and returns updated values
* x[0] and x[1] contain the new values of X and Y
* x[2] and x[3] contain the previous values
* @param t value of tangent vector (updated by iteration)
*/
//***********************************************************************************
      public void iterateTangent(double[] x, double[] t) {             
      
           X = t[0];
           Y = t[1];
           if (x[1]<a[0]){
                  t[0]=a[1]*X;
                  t[1]=Y/a[0];
           }
           else{  
                t[0]=a[2]*X;
                t[1]=Y/(1-a[0]);
           }
      
      }   
//***********************************************************************************               
}
