// 
//  
// Newton-Raphson root finding
//Numerical Analysis 
//    

import java.util.*;
import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;
import javax.swing.*;
//============= The function ================

class fb extends f_x
{
   public double func (double t)
   { return 75.0*Math.exp(-1.5*t)+20*Math.exp(-0.075*t)-15;}
}

//============= Derivative of the function ================
class dfb extends f_x
{
   public double func (double t)
   { return 75.0*(-1.5)*Math.exp(-1.5*t)+20*(-0.0075)*Math.exp(-0.075*t);}
}
//===========================================================


public class NA5
{	
public static double newton(f_x f,f_x df,double x)
{
int nmax=100;
double tolerance=1.0e-10;
double fx,dfx;
for(int i=0;i<nmax;i++)
{
  fx=f.func(x);
  dfx=f.dfunc(x);
  x-=fx/dfx;
  System.out.println("i="+i+"x="+x+"fx="+fx+"dfx = "+dfx);
  if(Math.abs(fx)<tolerance) { return x;}
}
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 x;
}

     public static void main (String args[])  
     { 
	 fb f=new fb();
	 dfb df=new dfb();
     double x0;
     x0=Double.parseDouble(JOptionPane.showInputDialog(" First guess for the root : "));
     double r= newton(f,df,x0);
     JOptionPane.showMessageDialog(null," Root of the function  : "+r+"\nFunction value : "+f.func(r),
     "Newton-Raphson root finding method : ",JOptionPane.PLAIN_MESSAGE);
     } 
}