import java.io.*;
import javax.swing.*;
import javax.tools.*;
import java.util.*;
import java.lang.Integer;
import java.awt.*;
import java.awt.event.*;
import java.awt.font.*;
import java.awt.geom.*;
import java.awt.image.*;
import javax.swing.*;
import java.util.Locale;
import java.text.*;
import java.util.*;
import javax.swing.table.*;

class ce2I
{ 	 public double r;	
	 public ce2I(double x1,double x2,double x3) 
	 {     
        f2D ff=new f2D();
        r= inverseinter2Droot(ff,x1,x2,x3);
     }
public static double inverseinter2Droot(f_x f,double x1,double x2,double x3)
{
// Inverse quadratic Lagrange interpolation
double test;
double p=0;
double es,ea;
double f1,f2,f3,fp;
int maxit=100,iter=0;
double tol=1.0e-10;
es=0.0000001;
ea=0.001;
f1=f.func(x1);
f2=f.func(x2);
f3=f.func(x3);
if(f1==0) return x1;
else if(f2==0) return x2;
else if(f3==0) return x3; 
if(f1*f3>0) System.out.println("Root is not existed in the given region");
while((ea>es)&&(iter<maxit))
{	p=-(f2*f3*x1*(f2-f3)+f3*f1*x2*(f3-f1)+f1*f2*x3*(f1-f2))/((f1-f2)*(f2-f3)*(f3-f1));
    fp=f.func(p);
    ea=Math.abs(x3-p);
	if(Math.abs(f3)<tol) return x3;        
    if(p>x3) {x1=x3;f1=f3;x3=p;f3=fp;}
    else if(p<x3) {x2=x3;f2=f3;x3=p;f3=fp;}
    iter++;
} 
if(iter>=maxit) JOptionPane.showMessageDialog(null,"Warning : MAximum number of iteration is exceeded \n"+
   " çözüm geçerli olmiyabilir","MAXİMUM ITERATION NUMBER WARNING",JOptionPane.WARNING_MESSAGE);
return p;
}


}
