bisect Interface

public interface bisect

Find root of a function in an interval using bisection.

Parameters:

  • f : function to find root of
  • a, b : interval to search for root
  • xtol : absolute tolerance, optional, default 2e-12
  • rtol : relative tolerance, optional, default 1e-15
  • maxiter : maximum number of iterations, optional, default 100

Returns:

  • x : root of f in [a, b]
  • info : solver_info_t structure, optional

The function f must be continuous, and f(a) and f(b) must have opposite signs.

If the solver converges, info%converged is true and info%iterations is the number of iterations required. If the solver does not converge, info%converged is false and info%iterations is the maximum number of iterations.

The convergence criterion is abs(x - xa) < xtol + rtol*abs(x) where xa is the left endpoint of the current interval.


Module Procedures

private function bisect_real64(f, a, b, xtol, rtol, maxiter, info) result(x)

Impementation of bisect for real64

Arguments

Type IntentOptional Attributes Name
procedure(func64) :: f

function to find root of

real(kind=rkind), intent(in) :: a

interval to search for root

real(kind=rkind), intent(in) :: b

interval to search for root

real(kind=rkind), intent(in), optional :: xtol

absolute tolerance

real(kind=rkind), intent(in), optional :: rtol

relative tolerance

integer, intent(in), optional :: maxiter

maximum number of iterations

type(solver_info_t), intent(out), optional :: info

solver info

Return Value real(kind=rkind)

private function bisect_real32(f, a, b, xtol, rtol, maxiter, info) result(x)

Impementation of bisect for real32

Arguments

Type IntentOptional Attributes Name
procedure(func32) :: f

function to find root of

real(kind=rkind), intent(in) :: a

interval to search for root

real(kind=rkind), intent(in) :: b

interval to search for root

real(kind=rkind), intent(in), optional :: xtol

absolute tolerance

real(kind=rkind), intent(in), optional :: rtol

relative tolerance

integer, intent(in), optional :: maxiter

maximum number of iterations

type(solver_info_t), intent(out), optional :: info

solver info

Return Value real(kind=rkind)