/*************************    Program 2.6    ****************************/
/*                                                                      */
/************************************************************************/
/* Please Note:                                                         */
/*                                                                      */
/* (1) This computer program is written by Tao Pang in conjunction with */
/*     his book, "An Introduction to Computational Physics," published  */
/*     by Cambridge University Press in 1997.                           */
/*                                                                      */
/* (2) No warranties, express or implied, are made for this program.    */
/*                                                                      */
/************************************************************************/

#include <stdio.h>
#include <math.h>
#define f(x) (exp(x)*log(x)-x*x)
#define d(x) (exp(x)*(log(x)+1/x)-2*x)

main()
/* This program uses the Newton method to find the root of
   f(x)=exp(x)*ln(x)-x*x=0.  Copyright (c) Tao Pang 1997. */
{
int istep;
double dl = 1e-6;
double a, b, x0, dx;

a = 1; b = 2;
dx = b-a;
x0 = (a+b)/2;
istep = 0;
while (fabs(dx) > dl)
  {
  dx  = f(x0)/d(x0);
  x0 -= dx;
  istep++;
  }
printf("%4d %16.8lf %16.8lf\n", istep,x0,dx);
}
