c************************************************** SUBROUTINE NEWTON (x0,er,nmax,xr,ea,fr) c************************************************** c Routs of a nonlinear function FF c Newton-Raphson method c IMPLICIT REAL*8 (a-h, o-z) c c-- initial values niter=0 xold=x0 fr=FF(xold) c c___ start of iterations _______________ c write(*,*) ' niter xr ea fr ' DO niter=niter+1 fgr=FD1(xold) IF(fgr .NE. 0.) THEN xr=xold-fr/fgr ELSE WRITE(*,*) 'error! zero derivative' RETURN ENDIF c-- xr is a roote? fr=FF(xr) if(fr. EQ. 0.) THEN ea=0. EXIT ENDIF c-- relative (or absolute) error IF (xr .NE. 0.) THEN ea=ABS((xr-xold)/xr) ELSE ea=ABS(xr-xold) ENDIF c-- monitoring (optional) WRITE(*,901) niter,xr,ea,fr c-- exit checks IF (ea .LE. er) EXIT IF (niter .GE. nmax) THEN WRITE(*,*) 'warning! iterations limit' EXIT ENDIF xold=xr END DO RETURN 901 FORMAT(2X,I4,E20.10,2E20.6) END