PROGRAM bsectst2
!
! Programmer H. L. Morrison
!
! Date 6 November 1985
!
! Revisions 15 April 1988 (include BSECT)
! 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.
!
! Try this program with intervals such as (.1, 1), (.01, .1),
! (.001, .01), etc. What is going on?
!
! Functions used f, SIN
!
! 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 = SIN(1.0 / x)
END FUNCTION