import java.io.*;

class SCO11N
{ 
   public static double[] inverseDifference(double xi[],double yi[])
  {
	 int n=xi.length;
	 double d[]=new double[n+1];
	 for(int i=0;i<n;i++)
	    d[i]=yi[i];	    
     for(int m=1;m<=n;m++)
     { for(int k=n;k>=m;k--)
         {d[k-1]=(xi[k-1]-xi[m-2])/(d[k-1]-d[m-2]);}
     }
     return d;
  }
  	
  public static double  funcSurekliBolme(double xi[],double yi[],double x)
  {
	 int n=xi.length; 
	 double F[]=inverseDifference(xi,yi);
	 double fbar;
     fbar=F[n-1];
     for(int i=n-1;i>=0;i--)
       { fbar=F[i]+(x-xi[i])/fbar;  }
     return fbar; 
  }
  
 public static double[][]  funcSurekliBolme(double xi[],double yi[],int aradegersayisi)
 {
	//aradegersayisi:  x--o--o--x--o--o--x zincirinde x deneysel noktalar ise
	// ara değer sayısı 2 dir
	int n=xi.length;
	int nn=(n-1)*(aradegersayisi+1)+1;
	double z[][]=new double[2][nn];
    double dx=0;
    int k=0;
    int i;
    for(i=0;i<(n-1);i++)
       {  z[0][k]=xi[i];z[1][k]=funcSurekliBolme(xi,yi,z[0][k]);k++;
          for(int j=0;j<aradegersayisi;j++) 
             {dx=(xi[i+1]-xi[i])/((double)aradegersayisi+1.0);
          z[0][k]=z[0][k-1]+dx;z[1][k]=funcSurekliBolme(xi,yi,z[0][k]);k++;}
       }
       z[0][k]=xi[i];z[1][k]=funcSurekliBolme(xi,yi,z[0][k]);
    return z;
 }
      
  public static void main(String args[]) throws IOException
  {
  double x[]={-1,0,1,2};
  double y[]={2,1,3,2.5};
  double z1[][]=funcSurekliBolme(x,y,9);
  System.out.println("Newton interpolasyonu\n"+Matrix.toStringT(z1)); 
  Text.print(Text.T(z1),"Sürekli bölme interpolasyonu");
  Plot pp=new Plot(x,y);
  pp.setPlabel("sürekli bölme interpolasyonu yöntemi eğri uydurma");
  pp.setPlotType(0,20); 
  pp.addData(z1[0],z1[1]);
  pp.plot();
  }
}