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 ce2A 
{ 	 public double r;	
	 public ce2A(double x1,double x2) 
	 {     
        f2D ff=new f2D();
        r= false_position(ff,x1,x2);
     }

public static double false_position(f_x f,double xa,double xu)
{
//Modified False position root finding
double test;
double p=0;
double es,ea;
double fa,fp,fu;
int maxit=100,iter=0;
es=0.000001;
ea=1.1*es;
double xold;
int ia=0,iu=0;
fa=f.func(xa);
fu=f.func(xu);
p=xu;
double xpold;
while(iter<maxit && ea>es)
{
xpold=p;	
if((iter%4)==0) p=(xa+xu)/2.0;
else p=xu-fu*(xa-xu)/(fa-fu);
fp=f.func(p);
iter++;
if(p!=0) ea=Math.abs((p-xpold)/p)*100.0;
test=fa*fp;
if(test<0) {xu=p;fu=f.func(xu);iu=0;ia++;if(ia>=2) fa/=2.0;}
else if(test>0) {xa=p;fa=f.func(xa);ia=0;iu+=1;if(iu>=2)fu/=2.0;}
else ea=0;
}
if(iter>=maxit) JOptionPane.showMessageDialog(null,"Maximum number of iteration is exceeded \n"+
   " result might not be valid","MAKSİMUM NUMBER OF ITERATION WARNING",JOptionPane.WARNING_MESSAGE); 
return p;
}
}
