// Numerical Analysis
// 
//  
// Root finding with secant method 
// two initia root estimation 
//  
import java.util.*;
import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;
import javax.swing.*;

//============= Function definition ================

class fb extends f_x
{
   public double func (double T)
   { return 0.971875+0.000165178571429*T+ 0.000001339285714*T*T-1.2;}
}

public class NA7
{
public static double secant(f_x f,double x0,double x1)
{
int nmax=500;
double tolerance=1.0e-10;
double fx0,fx1;
double x;
fx0=f.func(x0);
for(int i=0;i<nmax;i++)
{
  fx1=f.func(x1);
  x=x1-fx1*(x1-x0)/(fx1-fx0);
  x0=x1;
  fx0=fx1;
  x1=x;
  if(Math.abs(fx1)<tolerance) { return x1;}
}
JOptionPane.showMessageDialog(null,"Warning : MAximum number of iteration is exceeded \n"+
   " çözüm geçerli olmıyabilir","MAXİMUM ITERATION NUMBER WARNING",JOptionPane.WARNING_MESSAGE);
return x1;
}

     public static void main (String args[])  
     {
	 fb f=new fb();
     double x0,x1;
     x0=Double.parseDouble(JOptionPane.showInputDialog(" First guess for the root : "));
     x1=Double.parseDouble(JOptionPane.showInputDialog(" Second guess for the root : "));
     double r= secant(f,x0,x1);
     JOptionPane.showMessageDialog(null," the root  : "+r+"\nfunction value : "+f.func(r),
     "Secant root finding method : ",JOptionPane.PLAIN_MESSAGE);
     System.exit(0);
     } 
}