This module re-implements a subset of SciPy optimization routines in Fortran.
Find root of a function in an interval using bisection.
Parameters:
Returns:
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.
Impementation of bisect for real64
Type | Intent | Optional | 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 |
Impementation of bisect for real32
Type | Intent | Optional | 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 |
Find root of a function using Newton’s or secant method.
Parameters:
Returns:
The function f must be continuous, x0 should be close enough to the root.
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.
Impementation of bisect for real64
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
procedure(func64) | :: | f |
function to find root of |
|||
real(kind=rkind), | intent(in) | :: | x0 |
initial estimate of root |
||
procedure(func64), | optional | :: | fprime |
function to find root of |
||
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 |
Find root of a function using given method
Parameters:
Returns:
The function f must be continuous, x0 should be close enough to the root.
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.
Find root of a function using given method
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
procedure(func64) | :: | f |
function to find root of |
|||
real(kind=rkind), | intent(in), | optional | :: | x0 |
initial estimate of root |
|
real(kind=rkind), | intent(in), | optional | :: | a |
interval to search for root |
|
real(kind=rkind), | intent(in), | optional | :: | b |
interval to search for root |
|
procedure(func64), | optional | :: | fprime |
function to find root of |
||
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 |
|
character(len=*), | intent(in), | optional | :: | method |
method to use |
|
type(solver_info_t), | intent(out), | optional | :: | info |
solver info |
Structure containing information about a solver convergence
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
logical, | public | :: | converged | = | .false. |
true if solver converged |
|
integer, | public | :: | iterations | = | 0 |
number of iterations |