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 ce2G
{ 	 public double r;	
	 public ce2G(double x1,double x2,double x3) 
	 {     
        f2D ff=new f2D();
        r= muller(ff,x1,x2,x3);
     }
public static double muller(f_x f,double x0,double x1,double x2)
{
//Finding real roots by using Muller method
//orta xr noktasindan +/- h kadar giderek diğer 2 noktaya ulaşiyoruz.
int maxit=100;
double xr=x0;
int iter=0;
double es1=0.001;
double es=es1;
double ea=1.1*es;
double h0,h1;
double d0,d1;
double a,b,c;
double fx0,fx1,fx2;
double determinant;
double den;
double dxr;
while(iter<maxit && ea>es)
{
    fx0=f.func(x0);
    fx1=f.func(x1);
    fx2=f.func(x2);
    h0=x1-x0;
    h1=x2-x1;
    d0=(fx1-fx0)/h0;
    d1=(fx2-fx1)/h1;
    a=(d1-d0)/(h1+h0);
    b=a*h1+d1;
    c=fx2;
    determinant=b*b-4.0*a*c;
    if(determinant<=0) determinant=0;//we do not want to calculate complex roots here
    else determinant=Math.sqrt(determinant);
    if(Math.abs(b+determinant)>Math.abs(b-determinant)) {den=b+determinant;;}
    else {den=b-determinant;}
    dxr=-2*c/den;
    xr=x2+dxr;
    ea=Math.abs((xr-x2)/xr)*100;
    iter++;
    x0=x1;
    x1=x2;
    x2=xr;
} 
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 xr;
}

}
