PROGRAM bsectst1
!
! Programmer H. L. Morrison
!
! Date 6 November 1985
!
! Revisions 15 April 1988
! January 4, 2000 by Br. David Carlson to run under Fortran 90
! May 2, 2004 by Br. David Carlson
!
! Purpose To demonstrate the use of a library of subroutines
! with the subroutine BISEC which computes a root of a non-linear
! equation of the form f(x) = 0 by using the method of bisection.
!
! To find a root, use an interval such as (1, 2) or (4, 5).
! Also try (2, 4) and (1, 5) and explain the results.
!
! Functions used EXP, f, COS
!
! Subroutines used BISEC
IMPLICIT NONE
INTEGER::i, imax
REAL::xleft, xright, xtol, root
! Function used:
REAL::f
xtol = 1.0E-5
imax = 25
WRITE (*, *) 'Enter left and right values for the endpoints of the interval'
READ (*, *) xleft, xright
CALL BISEC(xleft, xright, xtol, imax, i, root)
WRITE (*, *) ' '
WRITE (*, *) 'The approximate value of the root is ', root
WRITE (*, *) 'This root was obtained after ', i, ' iterations'
WRITE (*, *) 'As a check, function value at this approx root = ', f(root)
END PROGRAM
! Given: x A real value.
! Task: To compute the value of f(x).
! Return: This value in the function name.
REAL FUNCTION f(x)
IMPLICIT NONE
REAL, INTENT(IN)::x
f = x * EXP(-x) - COS(x)
END FUNCTION