program test_newton use newton_root integer:: ierr real(DOUBLE):: x0,tol ! ! Read the initial guess (x0) and convergence tolerance from the ! standard input. ! read(5,*) x0,tol ! ! Find the root and print the results. ! call newton(myfunc,myderiv,x0,tol,ierr) if(ierr.eq.0) then write(6,*) x0 else write(6,*) 'no convergence' endif stop contains !----------- ! MYFUNC is the function whose root we seek. This is just an example. ! function myfunc(x) real(DOUBLE):: myfunc real(DOUBLE),intent(in):: x ! myfunc=x**2-2.0 ! for finding sqrt(2) return end function myfunc !----------- ! MYDERIV is the derivative of function whose root we seek. ! This is just an example. ! function myderiv(x) real(DOUBLE):: myderiv real(DOUBLE),intent(in):: x ! myderiv=2.0*x return end function myderiv !----------- end program test_newton