C****************************************************************
C*****   EXERCISE 1, 2007    ***** SIMPLE APPLICATION       *****
C****************************************************************
C
C       USE OF THE NEWTON-RAPHSON METHOD FOR SOLVING FOR ROOTS 
C       OF EQUATIONS
C
C       EN EXAMPLE USING THE SIMPLE EQUATION F(X)=X^2-2X+1=0 
C
C       READ INITIAL GUESS, X0, MAXIMUM NO. OF ITERATIONS, ITMAX,
C       AND CONVERGENCE CRITERION, EPS
C	
C****************************************************************
C	 
C-----DECLARATIONS
C      
      IMPLICIT NONE
      REAL X0,X,DX,EPS,RE
      INTEGER I,ITMAX,K
C
C-----OPEN FILES
C
      OPEN(UNIT=10,FILE="SIMPLE.IN",STATUS="OLD")
      OPEN(UNIT=11,FILE="SIMPLE.OUT",STATUS="UNKNOWN")
C
C-----READ AND WRITE INPUT DATA
C
   10 READ(10,*)X0,ITMAX,EPS
      WRITE(11,200)X0,ITMAX,EPS
C
C---------------------------START NEWTONIAN ITERATION
      X=X0
      DO 40 K=1,ITMAX
      DX =-(X**2-2*x+1)/(2*X-2)
      X=X+DX
C---------------------------PRINTOUT
      WRITE(11,201)K,X
C---------------------------CHECK FOR CONVERGENCE
      RE=ABS(DX)
      IF(RE>EPS)GO TO 40
      GO TO 50
   40 CONTINUE
      WRITE(11,202)
   50 CONTINUE
C
  200 FORMAT(" INITIAL GUESS OF SOLUTION (X0)", F5.2,/,
     *       " MAX NO OF ITERATIONS ALLOWED", I5,/,
     *       " CONVERGENCE CRITERION", F8.5,/)
  201 FORMAT(" ITERATION ",I3,"  X= ",F8.5)
  202 FORMAT(17H0 NO CONVERGENCE  )
C
      END
