program secante !! 25-May-2010 implicit real*8 (a-h,o-z) c....... by Dario Mitnik c....... Finding the root of the function finput(x) by Secant Method external finput,dfinput data rzero,one,two/0.0d0,1.0d0,2.0d0/ c....... files used: c....... unit=20 -- secante.out (output) open(unit=20,file='secante.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*,' ' x1 = (a + b)/two x0 = x1 - x1/10.0d0 do 100 i=1,mxteps fx1 = finput(x1) dfx1 = dfinput(x1,x0) x2 = x1 - fx1/dfx1 dx = x2 - x1 write(20,555) x2,x1,dx,fx1 if (dabs(dx).le.tolerance) then write(20,555) x2,finput(x2) print*,' root = ',x2,' in ',i,' iterations' stop endif x0 = x1 x1 = x2 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(x1,x0) implicit real*8 (a-h,o-z) c....... derivative of input function data one,two/1.0d0,2.0d0/ dfinput = (finput(x1)-finput(x0))/(x1-x0) return end c c************************************************************************ c