rootfind Module

Provides subroutines implementing various root-finding algorithms, as well as a global bracket finder.


Contents


Subroutines

public subroutine bis_secant(error, fnctn, maxerr, maxsteps, steps, xcur, xleft, xright)

A root finder using the hybrid bisection-secant algorithm. Returns a computed value of the root within xleft and xright once error < maxerr or has run maximum number of iterations.

Arguments

Type IntentOptional AttributesName
real(kind=8), intent(out) :: error

A real variable in which an estimate of the error in the computed root will be stored and returned.

public pure function fnctn(x)

The Fortran function for which the root will be found. Must take only one real argument, return a real argument.

Arguments
Type IntentOptional AttributesName
real(kind=8), intent(in) :: x
Return Value real(kind=8)
real(kind=8), intent(in) :: maxerr

A real value which specifies the the maximum allowable error in the computed root. The subroutine terminates once the error passes below this level.

integer, intent(in) :: maxsteps

An integer value for the maximum number of iterations applied to the algorithm before terminating.

integer, intent(out) :: steps

Returns the number of iterations needed before error falls below maxerr (or returns maxsteps if that many iterations occur first).

real(kind=8), intent(out) :: xcur

A real variable in which the computed value of the root will be returned.

real(kind=8), intent(inout) :: xleft

A real value specifying lower bound within which to search for root.

real(kind=8), intent(inout) :: xright

A real value specifying upper bound within which to search for root.

public subroutine global_bis_sec(dx, error, fnctn, maxerr, maxsteps, numroots, roots, steps, verbose, xmax, xmin)

A subroutine which finds the values of all roots of a function (or as many as will fit into the provided arrays) within a given range of values. This subroutine uses the hybrid bisection-secant root-finding algorithm.

Arguments

Type IntentOptional AttributesName
real(kind=8), intent(inout) :: dx

The initial size of increment to use when examining function. Minimum interval will be 0.01 of this.

real(kind=8), intent(out), dimension(:):: error

A real array in which an estimate of the error in each computed root will be stored and returned.

public pure function fnctn(x)

The Fortran function for which the root will be found. Must take only one real argument, return a real argument.

Arguments
Type IntentOptional AttributesName
real(kind=8), intent(in) :: x
Return Value real(kind=8)
real(kind=8), intent(in) :: maxerr

A real value which specifies the the maximum allowable error in the computed root. The subroutine terminates once the error passes below this level.

integer, intent(in) :: maxsteps

An integer value for the maximum number of iterations applied to the algorithm before terminating.

integer, intent(out) :: numroots

An integer value which will return the number of roots for which brackets were found. A negative number indicates that an error occurred.

real(kind=8), intent(out), dimension(:):: roots

A real array in which the computed values of each root will be returned.

integer, intent(out), dimension(:):: steps

An integer array in which the number of iterations needed before error falls below maxerr for each root is stored and returned.

logical, intent(in) :: verbose

A logical variable which specifies whether to print progress to stdout as brackets found and at each iteration as root found. Also says whether to print a warning if 'dx' set to 'dxmin' during 'globrack' routine and if maximum number of iterations reached while finding root.

real(kind=8), intent(in) :: xmax

The upper limit of the range on which the subroutine will search for roots and brackets.

real(kind=8), intent(in) :: xmin

The lower limit of the range on which the subroutine will search for roots and brackets.

public subroutine global_brackets(brackets, dx, fnctn, numroots, verbose, xmax, xmin)

A global bracket finder. For a given function it finds values on each side of each of the function's roots within a given range.

Arguments

Type IntentOptional AttributesName
real(kind=8), intent(out), dimension(:,:):: brackets

A 2 by n real array in which the left and right brackets will be stored and returned. Will find up to n sets of brackets.

real(kind=8), intent(inout) :: dx

The initial size of increment to use when examining function. Minimum interval will be 0.01 of this.

public pure function fnctn(x)

The Fortran function for which the brackets will be found. Must take only one real argument, return a real argument.

Arguments
Type IntentOptional AttributesName
real(kind=8), intent(in) :: x
Return Value real(kind=8)
integer, intent(out) :: numroots

An integer value which will return the number of roots for which brackets were found. A negative number indicates that an error occurred.

logical, intent(in) :: verbose

A logical variable which specifies whether to print to stdout any bracket values which are found and warning messages when 'dx' set to 'dxmin'.

real(kind=8), intent(in) :: xmax

The upper limit of the range on which the subroutine will search for roots and brackets.

real(kind=8), intent(in) :: xmin

The lower limit of the range on which the subroutine will search for roots and brackets.