program newton !! 25-May-2010 implicit real*8 (a-h,o-z) c....... by Dario Mitnik c....... Finding the root of the function finput(x) by Newton-Raphson Method external finput,dfinput data rzero,one,two/0.0d0,1.0d0,2.0d0/ c....... files used: c....... unit=20 -- newton.out (output) open(unit=20,file='newton.out',status='unknown') c....... parameters for tolerance and convergence tolerance = 1.0d-6 mxteps = 50 print*,'give the interval for root finding (a and b)' read*,a print*,'a=:',a read*,b print*,'b=:',b print*,' ' x0 = (a + b)/two do 100 i=1,mxteps fx0 = finput(x0) dfx0 = dfinput(x0) x1 = x0 - fx0/dfx0 dx = x1 - x0 write(20,555) x0,x1,dx,fx0 if (dabs(dx).le.tolerance) then write(20,555) x1,finput(x1) print*,' root = ',x1,' in ',i,' iterations' stop endif x0 = x1 100 continue 555 format(3(1pg15.7,2x),1pg15.7) print*,' no convergence ' stop end c c************************************************************************ c double precision function finput(x) implicit real*8 (a-h,o-z) c....... input function finput = exp(x)*dlog(x) - x*x return end c c************************************************************************ c double precision function dfinput(x) implicit real*8 (a-h,o-z) c....... derivative of input function data one,two/1.0d0,2.0d0/ dfinput = exp(x)*(dlog(x) + one/x) - two*x return end c c************************************************************************ c