PROGRAM main REAL tol, x, xd, tmp1, tmp1d INTEGER r, it tol = 1.0e-3 r = 0 x = 6 WRITE(*, '(/, A, F3.1)') ' Initial guess: ', x xd = 1 WRITE(*, '(A, F3.1)') ' Initial guess direction: ', xd it = 20 WRITE(*, '(A, I4)') ' Iteration times: ', it WRITE(*, '(/, A)') " x f(x) f'(x)" DO CALL F_D( x, xd, tmp1, tmp1d ) WRITE(*, '(3(F9.5, X))') x, tmp1, tmp1d C x = x - ( tmp1 / tmp1d ) IF ( ABS( tmp1d ) < tol ) EXIT r = r + 1 IF ( r > it ) EXIT END DO END SUBROUTINE F( x, y ) REAL x, y IF ( x > 1 ) THEN y = x**2 ELSE y = 2-x**2 ENDIF END