program bisection !! 25-May-2010 implicit real*8 (a-h,o-z) c....... by Dario Mitnik c....... Finding the root of the function finput(x) by Bisection Method external finput data rzero,one,two/0.0d0,1.0d0,2.0d0/ c....... files used: c....... unit=20 -- bisection.out (output) open(unit=20,file='bisection.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*,' ' do 100 i=1,mxteps x1 = (a + b)/two fa = finput(a) fx1 = finput(x1) test = fa*fx1 if (test.lt.rzero) then b = x1 else a = x1 endif dx = b-a write(20,555) a,b,x1,fx1 if (dx.le.tolerance) then print*,' root = ',x1,' in ',i,' iterations' stop endif 100 continue 555 format(3(1pg12.7,2x),1pg15.7) 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