root_module Module

Root solver methods for:

  • Bracked interval
  • Without derivatives

Author

  • Jacob Williams

Note

The default real kind (wp) can be changed using optional preprocessor flags. This library was built with real kind: real(kind=real64) [8 bytes]


Uses

  • module~~root_module~~UsesGraph module~root_module root_module iso_fortran_env iso_fortran_env module~root_module->iso_fortran_env

Variables

Type Visibility Attributes Name Initial
integer, public, parameter :: root_module_rk = real64

real kind used by this module [8 bytes]

integer, private, parameter :: wp = root_module_rk

local copy of root_module_rk with a shorter name

integer, private, parameter :: name_len = 32

max length of the method names

real(kind=wp), private, parameter :: golden_ratio = (1.0_wp+sqrt(5.0_wp))/2.0_wp

golden ratio phi

type(root_method), public, parameter :: root_method_null = root_method(0, '')

enum type for an invalid method

type(root_method), public, parameter :: root_method_brent = root_method(1, 'brent')

enum type for brent method

type(root_method), public, parameter :: root_method_bisection = root_method(2, 'bisection')

enum type for bisection method

type(root_method), public, parameter :: root_method_regula_falsi = root_method(3, 'regula_falsi')

enum type for regula_falsi method

type(root_method), public, parameter :: root_method_illinois = root_method(4, 'illinois')

enum type for illinois method

type(root_method), public, parameter :: root_method_anderson_bjorck = root_method(5, 'anderson_bjorck')

enum type for anderson_bjorck method

type(root_method), public, parameter :: root_method_ridders = root_method(6, 'ridders')

enum type for ridders method

type(root_method), public, parameter :: root_method_pegasus = root_method(7, 'pegasus')

enum type for pegasus method

type(root_method), public, parameter :: root_method_bdqrf = root_method(8, 'bdqrf')

enum type for bdqrf method

type(root_method), public, parameter :: root_method_muller = root_method(9, 'muller')

enum type for muller method

type(root_method), public, parameter :: root_method_brenth = root_method(10, 'brenth')

enum type for brenth method

type(root_method), public, parameter :: root_method_brentq = root_method(11, 'brentq')

enum type for brentq method

type(root_method), public, parameter :: root_method_chandrupatla = root_method(12, 'chandrupatla')

enum type for chandrupatla method

type(root_method), public, parameter :: root_method_toms748 = root_method(13, 'toms748')

enum type for toms748 method

type(root_method), public, parameter :: root_method_zhang = root_method(14, 'zhang')

enum type for zhang method

type(root_method), public, parameter :: root_method_anderson_bjorck_king = root_method(15, 'anderson_bjorck_king')

enum type for anderson_bjorck_king method

type(root_method), public, parameter :: root_method_blendtf = root_method(16, 'blendtf')

enum type for blendtf method

type(root_method), public, parameter :: root_method_barycentric = root_method(17, 'barycentric')

enum type for barycentric method

type(root_method), public, parameter :: root_method_itp = root_method(18, 'itp')

enum type for itp method

type(root_method), public, parameter, dimension(*) :: set_of_root_methods = [root_method_brent, root_method_bisection, root_method_regula_falsi, root_method_illinois, root_method_anderson_bjorck, root_method_ridders, root_method_pegasus, root_method_bdqrf, root_method_muller, root_method_brenth, root_method_brentq, root_method_chandrupatla, root_method_toms748, root_method_zhang, root_method_anderson_bjorck_king, root_method_blendtf, root_method_barycentric, root_method_itp]

list of the available methods (see root_scalar)


Interfaces

public interface root_scalar

  • private subroutine root_scalar_by_name(method, fun, ax, bx, xzero, fzero, iflag, ftol, rtol, atol, maxiter, fax, fbx, bisect_on_failure)

    Non-object-oriented wrapper.

    Arguments

    Type IntentOptional Attributes Name
    character(len=*), intent(in) :: method

    the method to use

    procedure(func2) :: fun

    user function to find the root of

    real(kind=wp), intent(in) :: ax

    left endpoint of initial interval

    real(kind=wp), intent(in) :: bx

    right endpoint of initial interval

    real(kind=wp), intent(out) :: xzero

    abscissa approximating a zero of f in the interval ax,bx

    real(kind=wp), intent(out) :: fzero

    value of f at the root (f(xzero))

    integer, intent(out) :: iflag

    status flag (-1=error, 0=root found, -999=invalid method)

    real(kind=wp), intent(in), optional :: ftol

    absolute tolerance for f=0

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

    relative tol for x

    real(kind=wp), intent(in), optional :: atol

    absolute tol for x

    integer, intent(in), optional :: maxiter

    maximum number of iterations

    real(kind=wp), intent(in), optional :: fax

    if f(ax) is already known, it can be input here

    real(kind=wp), intent(in), optional :: fbx

    if f(bx) is already known, it can be input here

    logical, intent(in), optional :: bisect_on_failure

    if true, then if the specified method fails, it will be retried using the bisection method. (default is False). Note that this can use up to maxiter additional function evaluations.

  • private subroutine root_scalar_by_type(method, fun, ax, bx, xzero, fzero, iflag, ftol, rtol, atol, maxiter, fax, fbx, bisect_on_failure)

    Non-object-oriented wrapper.

    Arguments

    Type IntentOptional Attributes Name
    type(root_method), intent(in) :: method

    the method to use

    procedure(func2) :: fun

    user function to find the root of

    real(kind=wp), intent(in) :: ax

    left endpoint of initial interval

    real(kind=wp), intent(in) :: bx

    right endpoint of initial interval

    real(kind=wp), intent(out) :: xzero

    abscissa approximating a zero of f in the interval ax,bx

    real(kind=wp), intent(out) :: fzero

    value of f at the root (f(xzero))

    integer, intent(out) :: iflag

    status flag (-1=error, 0=root found, -999=invalid method)

    real(kind=wp), intent(in), optional :: ftol

    absolute tolerance for f=0

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

    relative tol for x

    real(kind=wp), intent(in), optional :: atol

    absolute tol for x

    integer, intent(in), optional :: maxiter

    maximum number of iterations

    real(kind=wp), intent(in), optional :: fax

    if f(ax) is already known, it can be input here

    real(kind=wp), intent(in), optional :: fbx

    if f(bx) is already known, it can be input here

    logical, intent(in), optional :: bisect_on_failure

    if true, then if the specified method fails, it will be retried using the bisection method. (default is False). Note that this can use up to maxiter additional function evaluations.


Abstract Interfaces

abstract interface

  • private function func(me, x) result(f)

    Interface to the function to be minimized (Object-oriented version). It should evaluate f(x) for any x in the interval (ax,bx)

    Arguments

    Type IntentOptional Attributes Name
    class(root_solver), intent(inout) :: me
    real(kind=wp), intent(in) :: x

    independant variable

    Return Value real(kind=wp)

    f(x)

abstract interface

  • private function func2(x) result(f)

    Interface to the function to be minimized (Functional version). It should evaluate f(x) for any x in the interval (ax,bx)

    Arguments

    Type IntentOptional Attributes Name
    real(kind=wp), intent(in) :: x

    independant variable

    Return Value real(kind=wp)

    f(x)

abstract interface

  • private subroutine root_f(me, ax, bx, fax, fbx, xzero, fzero, iflag)

    Root solver function interface

    Arguments

    Type IntentOptional Attributes Name
    class(root_solver), intent(inout) :: me
    real(kind=wp), intent(in) :: ax

    left endpoint of initial interval

    real(kind=wp), intent(in) :: bx

    right endpoint of initial interval

    real(kind=wp), intent(in) :: fax

    f(ax)

    real(kind=wp), intent(in) :: fbx

    f(bx)

    real(kind=wp), intent(out) :: xzero

    abscissa approximating a zero of f in the interval ax,bx

    real(kind=wp), intent(out) :: fzero

    value of f at the root (f(xzero))

    integer, intent(out) :: iflag

    status flag


Derived Types

type, public ::  root_method

a type to define enums for the different methods

Components

Type Visibility Attributes Name Initial
integer, private :: id = 0

unique ID code for the method

character(len=name_len), private :: name = ''

name of the method

type, public ::  root_solver

abstract class for the root solver methods

Components

Type Visibility Attributes Name Initial
procedure(func), private, pointer :: f => null()

user function to find the root of

real(kind=wp), private :: ftol = 0.0_wp

absolute tolerance for f=0

real(kind=wp), private :: rtol = 1.0e-6_wp

relative tol for x

real(kind=wp), private :: atol = 1.0e-12_wp

absolute tol for x [not used by all methods]

integer, private :: maxiter = 2000

maximum number of iterations [not used by all methods]

Type-Bound Procedures

procedure, public :: initialize => initialize_root_solver ../../

initialize the class [must be called first]

procedure, public :: solve ../../

main routine for finding the root

procedure(root_f), private, deferred :: find_root

root solver function. Meant to be called from solve, which handles some common startup tasks. All these routines assume that and have opposite signs.

procedure, private :: get_fa_fb
procedure, private :: converged
procedure, private :: solution ../../

to check f value against ftol

type, public, extends(root_solver) ::  brent_solver

Classic brent (zeroin) root solver

Type-Bound Procedures

procedure, public :: initialize => initialize_root_solver ../../

initialize the class [must be called first]

procedure, public :: solve ../../

main routine for finding the root

procedure, public :: find_root => brent

type, public, extends(root_solver) ::  bisection_solver

Classic bisection root solver

Type-Bound Procedures

procedure, public :: initialize => initialize_root_solver ../../

initialize the class [must be called first]

procedure, public :: solve ../../

main routine for finding the root

procedure, public :: find_root => bisection

type, public, extends(root_solver) ::  regula_falsi_solver

Classic Regula Falsi root solver

Type-Bound Procedures

procedure, public :: initialize => initialize_root_solver ../../

initialize the class [must be called first]

procedure, public :: solve ../../

main routine for finding the root

procedure, public :: find_root => regula_falsi

type, public, extends(root_solver) ::  illinois_solver

Illinois (modified Regula Falsi) root solver

Type-Bound Procedures

procedure, public :: initialize => initialize_root_solver ../../

initialize the class [must be called first]

procedure, public :: solve ../../

main routine for finding the root

procedure, public :: find_root => illinois

type, public, extends(root_solver) ::  anderson_bjorck_solver

anderson bjorck root solver

Type-Bound Procedures

procedure, public :: initialize => initialize_root_solver ../../

initialize the class [must be called first]

procedure, public :: solve ../../

main routine for finding the root

procedure, public :: find_root => anderson_bjorck

type, public, extends(root_solver) ::  ridders_solver

ridders root solver

Type-Bound Procedures

procedure, public :: initialize => initialize_root_solver ../../

initialize the class [must be called first]

procedure, public :: solve ../../

main routine for finding the root

procedure, public :: find_root => ridders

type, public, extends(root_solver) ::  pegasus_solver

pegasus root solver

Type-Bound Procedures

procedure, public :: initialize => initialize_root_solver ../../

initialize the class [must be called first]

procedure, public :: solve ../../

main routine for finding the root

procedure, public :: find_root => pegasus

type, public, extends(root_solver) ::  bdqrf_solver

bdqrf root solver

Type-Bound Procedures

procedure, public :: initialize => initialize_root_solver ../../

initialize the class [must be called first]

procedure, public :: solve ../../

main routine for finding the root

procedure, public :: find_root => bdqrf

type, public, extends(root_solver) ::  muller_solver

muller root solver

Type-Bound Procedures

procedure, public :: initialize => initialize_root_solver ../../

initialize the class [must be called first]

procedure, public :: solve ../../

main routine for finding the root

procedure, public :: find_root => muller

type, public, extends(root_solver) ::  brenth_solver

brenth root solver

Type-Bound Procedures

procedure, public :: initialize => initialize_root_solver ../../

initialize the class [must be called first]

procedure, public :: solve ../../

main routine for finding the root

procedure, public :: find_root => brenth

type, public, extends(root_solver) ::  brentq_solver

brentq root solver

Type-Bound Procedures

procedure, public :: initialize => initialize_root_solver ../../

initialize the class [must be called first]

procedure, public :: solve ../../

main routine for finding the root

procedure, public :: find_root => brentq

type, public, extends(root_solver) ::  chandrupatla_solver

chandrupatla root solver

Type-Bound Procedures

procedure, public :: initialize => initialize_root_solver ../../

initialize the class [must be called first]

procedure, public :: solve ../../

main routine for finding the root

procedure, public :: find_root => chandrupatla

type, public, extends(root_solver) ::  toms748_solver

TOMS748 root solver

Type-Bound Procedures

procedure, public :: initialize => initialize_root_solver ../../

initialize the class [must be called first]

procedure, public :: solve ../../

main routine for finding the root

procedure, public :: find_root => toms748

type, public, extends(root_solver) ::  zhang_solver

zhang root solver

Type-Bound Procedures

procedure, public :: initialize => initialize_root_solver ../../

initialize the class [must be called first]

procedure, public :: solve ../../

main routine for finding the root

procedure, public :: find_root => zhang

type, public, extends(root_solver) ::  anderson_bjorck_king_solver

anderson-bjorck-king root solver

Type-Bound Procedures

procedure, public :: initialize => initialize_root_solver ../../

initialize the class [must be called first]

procedure, public :: solve ../../

main routine for finding the root

procedure, public :: find_root => anderson_bjorck_king

type, public, extends(root_solver) ::  blendtf_solver

blendtf root solver

Type-Bound Procedures

procedure, public :: initialize => initialize_root_solver ../../

initialize the class [must be called first]

procedure, public :: solve ../../

main routine for finding the root

procedure, public :: find_root => blendtf

type, public, extends(root_solver) ::  barycentric_solver

barycentric root solver

Type-Bound Procedures

procedure, public :: initialize => initialize_root_solver ../../

initialize the class [must be called first]

procedure, public :: solve ../../

main routine for finding the root

procedure, public :: find_root => barycentric

type, public, extends(root_solver) ::  itp_solver

ITP root solver

Components

Type Visibility Attributes Name Initial
real(kind=wp), private :: k1 = 0.1_wp

from (0, inf)

real(kind=wp), private :: k2 = 0.98_wp*(1.0_wp+golden_ratio)

from [1, 1+phi]

integer, private :: n0 = 1

Type-Bound Procedures

procedure, public :: initialize => initialize_root_solver ../../

initialize the class [must be called first]

procedure, public :: solve ../../

main routine for finding the root

procedure, public :: find_root => itp
procedure, public :: set_optional_inputs => itp_optional_inputs

Functions

private pure function root_name_to_method(name) result(r)

Convert a root method name to the corresponding root_method enum type.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: name

method name

Return Value type(root_method)

the root_method enum type for that method

private function converged(me, a, b)

Determines convergence in x based on if the reltol or abstol is satisfied.

Arguments

Type IntentOptional Attributes Name
class(root_solver), intent(inout) :: me
real(kind=wp), intent(in) :: a

old value

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

new value

Return Value logical

private pure function bisect(x1, x2) result(x3)

Bisection step.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: x1
real(kind=wp), intent(in) :: x2

Return Value real(kind=wp)

point half way between x1 and x2

private function regula_falsi_step(x1, x2, f1, f2, ax, bx) result(x3)

Regula Falsi step. With a protection to fall back to bisection if:

Read more…

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: x1
real(kind=wp), intent(in) :: x2
real(kind=wp), intent(in) :: f1
real(kind=wp), intent(in) :: f2
real(kind=wp), intent(in) :: ax

original interval lower bound

real(kind=wp), intent(in) :: bx

original interval upper bound

Return Value real(kind=wp)

intersection of line connecting x1,x2 with x-axis

private pure function secant(x1, x2, f1, f2, ax, bx) result(x3)

Secent step. With a protection to fall back to bisection if:

Read more…

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: x1
real(kind=wp), intent(in) :: x2
real(kind=wp), intent(in) :: f1
real(kind=wp), intent(in) :: f2
real(kind=wp), intent(in) :: ax

original interval lower bound

real(kind=wp), intent(in) :: bx

original interval upper bound

Return Value real(kind=wp)

intersection of secant step with x-axis

private pure function lowercase(str) result(s_lower)

lowercase a string.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: str

input string

Return Value character(len=len=(len(str)))

lowercase version of the string

private function solution(me, x, f, xzero, fzero)

Returns true if this is a solution and sets xzero and fzero.

Arguments

Type IntentOptional Attributes Name
class(root_solver), intent(inout) :: me
real(kind=wp), intent(in) :: x
real(kind=wp), intent(in) :: f
real(kind=wp), intent(inout) :: xzero
real(kind=wp), intent(inout) :: fzero

Return Value logical


Subroutines

private subroutine initialize_root_solver(me, f, ftol, rtol, atol, maxiter)

Initialize the root_solver class.

Read more…

Arguments

Type IntentOptional Attributes Name
class(root_solver), intent(out) :: me
procedure(func) :: f

user function f(x) to find the root of

real(kind=wp), intent(in), optional :: ftol

absolute tolerance for f=0

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

relative tol for x

real(kind=wp), intent(in), optional :: atol

absolute tol for x

integer, intent(in), optional :: maxiter

maximum number of iterations

private subroutine root_scalar_by_name(method, fun, ax, bx, xzero, fzero, iflag, ftol, rtol, atol, maxiter, fax, fbx, bisect_on_failure)

Non-object-oriented wrapper.

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: method

the method to use

procedure(func2) :: fun

user function to find the root of

real(kind=wp), intent(in) :: ax

left endpoint of initial interval

real(kind=wp), intent(in) :: bx

right endpoint of initial interval

real(kind=wp), intent(out) :: xzero

abscissa approximating a zero of f in the interval ax,bx

real(kind=wp), intent(out) :: fzero

value of f at the root (f(xzero))

integer, intent(out) :: iflag

status flag (-1=error, 0=root found, -999=invalid method)

real(kind=wp), intent(in), optional :: ftol

absolute tolerance for f=0

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

relative tol for x

real(kind=wp), intent(in), optional :: atol

absolute tol for x

integer, intent(in), optional :: maxiter

maximum number of iterations

real(kind=wp), intent(in), optional :: fax

if f(ax) is already known, it can be input here

real(kind=wp), intent(in), optional :: fbx

if f(bx) is already known, it can be input here

logical, intent(in), optional :: bisect_on_failure

if true, then if the specified method fails, it will be retried using the bisection method. (default is False). Note that this can use up to maxiter additional function evaluations.

private subroutine root_scalar_by_type(method, fun, ax, bx, xzero, fzero, iflag, ftol, rtol, atol, maxiter, fax, fbx, bisect_on_failure)

Non-object-oriented wrapper.

Arguments

Type IntentOptional Attributes Name
type(root_method), intent(in) :: method

the method to use

procedure(func2) :: fun

user function to find the root of

real(kind=wp), intent(in) :: ax

left endpoint of initial interval

real(kind=wp), intent(in) :: bx

right endpoint of initial interval

real(kind=wp), intent(out) :: xzero

abscissa approximating a zero of f in the interval ax,bx

real(kind=wp), intent(out) :: fzero

value of f at the root (f(xzero))

integer, intent(out) :: iflag

status flag (-1=error, 0=root found, -999=invalid method)

real(kind=wp), intent(in), optional :: ftol

absolute tolerance for f=0

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

relative tol for x

real(kind=wp), intent(in), optional :: atol

absolute tol for x

integer, intent(in), optional :: maxiter

maximum number of iterations

real(kind=wp), intent(in), optional :: fax

if f(ax) is already known, it can be input here

real(kind=wp), intent(in), optional :: fbx

if f(bx) is already known, it can be input here

logical, intent(in), optional :: bisect_on_failure

if true, then if the specified method fails, it will be retried using the bisection method. (default is False). Note that this can use up to maxiter additional function evaluations.

private subroutine solve(me, ax, bx, xzero, fzero, iflag, fax, fbx, bisect_on_failure)

Main wrapper routine for all the methods.

Arguments

Type IntentOptional Attributes Name
class(root_solver), intent(inout) :: me
real(kind=wp), intent(in) :: ax

left endpoint of initial interval

real(kind=wp), intent(in) :: bx

right endpoint of initial interval

real(kind=wp), intent(out) :: xzero

abscissa approximating a zero of f in the interval ax,bx

real(kind=wp), intent(out) :: fzero

value of f at the root (f(xzero))

integer, intent(out) :: iflag

status flag (-1=error, 0=root found, -4=ax must be /= bx)

real(kind=wp), intent(in), optional :: fax

if f(ax) is already known, it can be input here

real(kind=wp), intent(in), optional :: fbx

if f(bx) is already known, it can be input here

logical, intent(in), optional :: bisect_on_failure

if true, then if the specified method fails, it will be retried using the bisection method. (default is False). Note that this can use up to maxiter additional function evaluations.

private subroutine get_fa_fb(me, ax, bx, fax, fbx, fa, fb)

Returns the function values at ax and bx to start the root finding algorithm.

Arguments

Type IntentOptional Attributes Name
class(root_solver), intent(inout) :: me
real(kind=wp), intent(in) :: ax

left endpoint of initial interval

real(kind=wp), intent(in) :: bx

right endpoint of initial interval

real(kind=wp), intent(in), optional :: fax

if f(ax) is already known, it can be input here

real(kind=wp), intent(in), optional :: fbx

if f(bx) is already known, it can be input here

real(kind=wp), intent(out) :: fa

f(ax) to use

real(kind=wp), intent(out) :: fb

f(ax) to use

private subroutine brent(me, ax, bx, fax, fbx, xzero, fzero, iflag)

Find a zero of the function in the given interval to within a tolerance , where is the relative machine precision defined as the smallest representable number such that .

Read more…

Arguments

Type IntentOptional Attributes Name
class(brent_solver), intent(inout) :: me
real(kind=wp), intent(in) :: ax

left endpoint of initial interval

real(kind=wp), intent(in) :: bx

right endpoint of initial interval

real(kind=wp), intent(in) :: fax

f(ax)

real(kind=wp), intent(in) :: fbx

f(ax)

real(kind=wp), intent(out) :: xzero

abscissa approximating a zero of f in the interval ax,bx

real(kind=wp), intent(out) :: fzero

value of f at the root (f(xzero))

integer, intent(out) :: iflag

status flag (0=root found)

private subroutine bisection(me, ax, bx, fax, fbx, xzero, fzero, iflag)

Compute the zero of the function f(x) in the interval ax,bx using the bisection method.

Read more…

Arguments

Type IntentOptional Attributes Name
class(bisection_solver), intent(inout) :: me
real(kind=wp), intent(in) :: ax

left endpoint of initial interval

real(kind=wp), intent(in) :: bx

right endpoint of initial interval

real(kind=wp), intent(in) :: fax

f(ax)

real(kind=wp), intent(in) :: fbx

f(ax)

real(kind=wp), intent(out) :: xzero

abscissa approximating a zero of f in the interval ax,bx

real(kind=wp), intent(out) :: fzero

value of f at the root (f(xzero))

integer, intent(out) :: iflag

status flag (0=root found, -2=max iterations reached)

private subroutine regula_falsi(me, ax, bx, fax, fbx, xzero, fzero, iflag)

Compute the zero of the function f(x) in the interval ax,bx using the regula falsi method.

Arguments

Type IntentOptional Attributes Name
class(regula_falsi_solver), intent(inout) :: me
real(kind=wp), intent(in) :: ax

left endpoint of initial interval

real(kind=wp), intent(in) :: bx

right endpoint of initial interval

real(kind=wp), intent(in) :: fax

f(ax)

real(kind=wp), intent(in) :: fbx

f(ax)

real(kind=wp), intent(out) :: xzero

abscissa approximating a zero of f in the interval ax,bx

real(kind=wp), intent(out) :: fzero

value of f at the root (f(xzero))

integer, intent(out) :: iflag

status flag (0=root found, -2=max iterations reached)

private subroutine illinois(me, ax, bx, fax, fbx, xzero, fzero, iflag)

Illinois method.

Read more…

Arguments

Type IntentOptional Attributes Name
class(illinois_solver), intent(inout) :: me
real(kind=wp), intent(in) :: ax

left endpoint of initial interval

real(kind=wp), intent(in) :: bx

right endpoint of initial interval

real(kind=wp), intent(in) :: fax

f(ax)

real(kind=wp), intent(in) :: fbx

f(ax)

real(kind=wp), intent(out) :: xzero

abscissa approximating a zero of f in the interval ax,bx

real(kind=wp), intent(out) :: fzero

value of f at the root (f(xzero))

integer, intent(out) :: iflag

status flag (0=root found, -2=max iterations reached)

private subroutine anderson_bjorck(me, ax, bx, fax, fbx, xzero, fzero, iflag)

Compute the zero of the function f(x) in the interval ax,bx using the Anderson-Bjorck method.

Read more…

Arguments

Type IntentOptional Attributes Name
class(anderson_bjorck_solver), intent(inout) :: me
real(kind=wp), intent(in) :: ax

left endpoint of initial interval

real(kind=wp), intent(in) :: bx

right endpoint of initial interval

real(kind=wp), intent(in) :: fax

f(ax)

real(kind=wp), intent(in) :: fbx

f(ax)

real(kind=wp), intent(out) :: xzero

abscissa approximating a zero of f in the interval ax,bx

real(kind=wp), intent(out) :: fzero

value of f at the root (f(xzero))

integer, intent(out) :: iflag

status flag (0=root found, -2=max iterations reached)

private subroutine ridders(me, ax, bx, fax, fbx, xzero, fzero, iflag)

Ridders method to find a root of f(x).

Read more…

Arguments

Type IntentOptional Attributes Name
class(ridders_solver), intent(inout) :: me
real(kind=wp), intent(in) :: ax

left endpoint of initial interval

real(kind=wp), intent(in) :: bx

right endpoint of initial interval

real(kind=wp), intent(in) :: fax

f(ax)

real(kind=wp), intent(in) :: fbx

f(ax)

real(kind=wp), intent(out) :: xzero

abscissa approximating a zero of f in the interval ax,bx

real(kind=wp), intent(out) :: fzero

value of f at the root (f(xzero))

integer, intent(out) :: iflag

status flag (0=root found, -2=max iterations reached, -3=singularity in the algorithm)

private subroutine pegasus(me, ax, bx, fax, fbx, xzero, fzero, iflag)

Pegasus method to find a root of f(x).

Read more…

Arguments

Type IntentOptional Attributes Name
class(pegasus_solver), intent(inout) :: me
real(kind=wp), intent(in) :: ax

left endpoint of initial interval

real(kind=wp), intent(in) :: bx

right endpoint of initial interval

real(kind=wp), intent(in) :: fax

f(ax)

real(kind=wp), intent(in) :: fbx

f(ax)

real(kind=wp), intent(out) :: xzero

abscissa approximating a zero of f in the interval ax,bx

real(kind=wp), intent(out) :: fzero

value of f at the root (f(xzero))

integer, intent(out) :: iflag

status flag (0=root found, -2=max iterations reached)

private subroutine bdqrf(me, ax, bx, fax, fbx, xzero, fzero, iflag)

Bisected Direct Quadratic Regula Falsi (BDQRF) root solver method to find the root of a 1D function.

Read more…

Arguments

Type IntentOptional Attributes Name
class(bdqrf_solver), intent(inout) :: me
real(kind=wp), intent(in) :: ax

left endpoint of initial interval

real(kind=wp), intent(in) :: bx

right endpoint of initial interval

real(kind=wp), intent(in) :: fax

f(ax)

real(kind=wp), intent(in) :: fbx

f(ax)

real(kind=wp), intent(out) :: xzero

abscissa approximating a zero of f in the interval ax,bx

real(kind=wp), intent(out) :: fzero

value of f at the root (f(xzero))

integer, intent(out) :: iflag

status flag (0=root found, -2=max iterations reached)

private subroutine muller(me, ax, bx, fax, fbx, xzero, fzero, iflag)

Improved Muller method (for real roots only). Will fall back to bisection if any step fails.

Read more…

Arguments

Type IntentOptional Attributes Name
class(muller_solver), intent(inout) :: me
real(kind=wp), intent(in) :: ax

left endpoint of initial interval

real(kind=wp), intent(in) :: bx

right endpoint of initial interval

real(kind=wp), intent(in) :: fax

f(ax)

real(kind=wp), intent(in) :: fbx

f(ax)

real(kind=wp), intent(out) :: xzero

abscissa approximating a zero of f in the interval ax,bx

real(kind=wp), intent(out) :: fzero

value of f at the root (f(xzero))

integer, intent(out) :: iflag

status flag (0=root found, -2=max iterations reached)

private subroutine brenth(me, ax, bx, fax, fbx, xzero, fzero, iflag)

Brent's method with hyperbolic extrapolation.

Read more…

Arguments

Type IntentOptional Attributes Name
class(brenth_solver), intent(inout) :: me
real(kind=wp), intent(in) :: ax

left endpoint of initial interval

real(kind=wp), intent(in) :: bx

right endpoint of initial interval

real(kind=wp), intent(in) :: fax

f(ax)

real(kind=wp), intent(in) :: fbx

f(ax)

real(kind=wp), intent(out) :: xzero

abscissa approximating a zero of f in the interval ax,bx

real(kind=wp), intent(out) :: fzero

value of f at the root (f(xzero))

integer, intent(out) :: iflag

status flag (0=root found, -2=max iterations reached)

private subroutine brentq(me, ax, bx, fax, fbx, xzero, fzero, iflag)

Classic Brent's method to find a zero of the function f on the sign changing interval [ax, bx], but with a different formula for the extrapolation step.

Read more…

Arguments

Type IntentOptional Attributes Name
class(brentq_solver), intent(inout) :: me
real(kind=wp), intent(in) :: ax

left endpoint of initial interval

real(kind=wp), intent(in) :: bx

right endpoint of initial interval

real(kind=wp), intent(in) :: fax

f(ax)

real(kind=wp), intent(in) :: fbx

f(ax)

real(kind=wp), intent(out) :: xzero

abscissa approximating a zero of f in the interval ax,bx

real(kind=wp), intent(out) :: fzero

value of f at the root (f(xzero))

integer, intent(out) :: iflag

status flag (0=root found, -2=max iterations reached)

private subroutine chandrupatla(me, ax, bx, fax, fbx, xzero, fzero, iflag)

Chandrupatla's method.

Read more…

Arguments

Type IntentOptional Attributes Name
class(chandrupatla_solver), intent(inout) :: me
real(kind=wp), intent(in) :: ax

left endpoint of initial interval

real(kind=wp), intent(in) :: bx

right endpoint of initial interval

real(kind=wp), intent(in) :: fax

f(ax)

real(kind=wp), intent(in) :: fbx

f(ax)

real(kind=wp), intent(out) :: xzero

abscissa approximating a zero of f in the interval ax,bx

real(kind=wp), intent(out) :: fzero

value of f at the root (f(xzero))

integer, intent(out) :: iflag

status flag (0=root found, -2=max iterations reached)

private subroutine toms748(me, ax, bx, fax, fbx, xzero, fzero, iflag)

TOMS748 rootfinding method.

Read more…

Arguments

Type IntentOptional Attributes Name
class(toms748_solver), intent(inout) :: me
real(kind=wp), intent(in) :: ax

left endpoint of initial interval

real(kind=wp), intent(in) :: bx

right endpoint of initial interval

real(kind=wp), intent(in) :: fax

f(ax)

real(kind=wp), intent(in) :: fbx

f(ax)

real(kind=wp), intent(out) :: xzero

abscissa approximating a zero of f in the interval ax,bx

real(kind=wp), intent(out) :: fzero

value of f at the root (f(xzero))

integer, intent(out) :: iflag

status flag (0=root found, -2=max iterations reached)

private subroutine zhang(me, ax, bx, fax, fbx, xzero, fzero, iflag)

Zhang's method (with corrections from Stage).

Read more…

Arguments

Type IntentOptional Attributes Name
class(zhang_solver), intent(inout) :: me
real(kind=wp), intent(in) :: ax

left endpoint of initial interval

real(kind=wp), intent(in) :: bx

right endpoint of initial interval

real(kind=wp), intent(in) :: fax

f(ax)

real(kind=wp), intent(in) :: fbx

f(ax)

real(kind=wp), intent(out) :: xzero

abscissa approximating a zero of f in the interval ax,bx

real(kind=wp), intent(out) :: fzero

value of f at the root (f(xzero))

integer, intent(out) :: iflag

status flag (0=root found, -2=max iterations reached)

private subroutine anderson_bjorck_king(me, ax, bx, fax, fbx, xzero, fzero, iflag)

Modified anderson-bjorck-king method. Same as anderson_bjorck, but with an extra initial bisection step.

Read more…

Arguments

Type IntentOptional Attributes Name
class(anderson_bjorck_king_solver), intent(inout) :: me
real(kind=wp), intent(in) :: ax

left endpoint of initial interval

real(kind=wp), intent(in) :: bx

right endpoint of initial interval

real(kind=wp), intent(in) :: fax

f(ax)

real(kind=wp), intent(in) :: fbx

f(ax)

real(kind=wp), intent(out) :: xzero

abscissa approximating a zero of f in the interval ax,bx

real(kind=wp), intent(out) :: fzero

value of f at the root (f(xzero))

integer, intent(out) :: iflag

status flag (0=root found, -2=max iterations reached)

private subroutine blendtf(me, ax, bx, fax, fbx, xzero, fzero, iflag)

BlendTF blended method of trisection and false position methods.

Read more…

Arguments

Type IntentOptional Attributes Name
class(blendtf_solver), intent(inout) :: me
real(kind=wp), intent(in) :: ax

left endpoint of initial interval

real(kind=wp), intent(in) :: bx

right endpoint of initial interval

real(kind=wp), intent(in) :: fax

f(ax)

real(kind=wp), intent(in) :: fbx

f(ax)

real(kind=wp), intent(out) :: xzero

abscissa approximating a zero of f in the interval ax,bx

real(kind=wp), intent(out) :: fzero

value of f at the root (f(xzero))

integer, intent(out) :: iflag

status flag (0=root found, -2=max iterations reached)

private subroutine barycentric(me, ax, bx, fax, fbx, xzero, fzero, iflag)

Barycentric interpolation method.

Read more…

Arguments

Type IntentOptional Attributes Name
class(barycentric_solver), intent(inout) :: me
real(kind=wp), intent(in) :: ax

left endpoint of initial interval

real(kind=wp), intent(in) :: bx

right endpoint of initial interval

real(kind=wp), intent(in) :: fax

f(ax)

real(kind=wp), intent(in) :: fbx

f(ax)

real(kind=wp), intent(out) :: xzero

abscissa approximating a zero of f in the interval ax,bx

real(kind=wp), intent(out) :: fzero

value of f at the root (f(xzero))

integer, intent(out) :: iflag

status flag (0=root found, -2=max iterations reached)

private subroutine itp_optional_inputs(me, k1, k2, n0)

For the itp method, set the optional inputs.

Arguments

Type IntentOptional Attributes Name
class(itp_solver), intent(inout) :: me
real(kind=wp), intent(in), optional :: k1

from (0, inf) [Default is 0.1]

real(kind=wp), intent(in), optional :: k2

from [1, 1+phi] [Default is 0.98*(1+phi)]

integer, intent(in), optional :: n0

[Default is 1

private subroutine itp(me, ax, bx, fax, fbx, xzero, fzero, iflag)

Compute the zero of the function f(x) in the interval ax,bx using the Interpolate Truncate and Project (ITP) method.

Read more…

Arguments

Type IntentOptional Attributes Name
class(itp_solver), intent(inout) :: me
real(kind=wp), intent(in) :: ax

left endpoint of initial interval

real(kind=wp), intent(in) :: bx

right endpoint of initial interval

real(kind=wp), intent(in) :: fax

f(ax)

real(kind=wp), intent(in) :: fbx

f(ax)

real(kind=wp), intent(out) :: xzero

abscissa approximating a zero of f in the interval ax,bx

real(kind=wp), intent(out) :: fzero

value of f at the root (f(xzero))

integer, intent(out) :: iflag

status flag (0=root found, -2=max iterations reached)

private pure subroutine choose_best(x1, x2, f1, f2, xbest, fbest)

Given two points with two function evaluations, choose the best one (the one closest to the root).

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(in) :: x1
real(kind=wp), intent(in) :: x2
real(kind=wp), intent(in) :: f1
real(kind=wp), intent(in) :: f2
real(kind=wp), intent(out) :: xbest
real(kind=wp), intent(out) :: fbest

private pure elemental subroutine swap(a, b)

Swap two real(wp) values.

Arguments

Type IntentOptional Attributes Name
real(kind=wp), intent(inout) :: a
real(kind=wp), intent(inout) :: b