MRFFL: MR Fortran Finance Library 2024-12-28
Computational Tools For Finance
|
Experimental root solvers that take a data payload in addition to a function. More...
Functions/Subroutines | |
subroutine, public | bisection (xc, x0_init, x1_init, f, r_dat, i_dat, x_epsilon, y_epsilon, max_itr, status, progress) |
Search for a root for the function f in the interval [x0_init, x1_init]. | |
subroutine, public | multi_bisection (xc, x0_init, x1_init, f, r_dat, i_dat, x_epsilon, y_epsilon, max_itr, status, progress) |
Use bisection() to search for a root for the function f in a list of intervals returning the first root found. | |
Experimental root solvers that take a data payload in addition to a function.
The idea is to avoid shared variables. This is especially difficult for nested functions because they require the resulting binary to have an executable stack – something frowned upon. Unfortuntly this code currently causes code generated by the NVIDIA HPC compiler to core dump. That's why this code is "experimental".
subroutine, public mrffl_solver_ne::bisection | ( | real(kind=rk), intent(out) | xc, |
real(kind=rk), intent(in) | x0_init, | ||
real(kind=rk), intent(in) | x1_init, | ||
procedure(func_to_solve_t) | f, | ||
real(kind=rk), dimension(:), intent(in) | r_dat, | ||
integer(kind=ik), dimension(:), intent(in) | i_dat, | ||
real(kind=rk), intent(in) | x_epsilon, | ||
real(kind=rk), intent(in) | y_epsilon, | ||
integer(kind=ik), intent(in) | max_itr, | ||
integer(kind=ik), intent(out) | status, | ||
logical, intent(in) | progress ) |
Search for a root for the function f in the interval [x0_init, x1_init].
The process is iterative. At each step the size of the search interval is cut in half. If the search interval gets too small (< x_epsilon), then the process is abandoned. If no zero is found after max_itr, then the process is abandoned.
xc | The solution (or last value tested if no solution is found) |
x0_init | Left side of search interval |
x1_init | Right side of search interval |
f | Function to solve for zero |
r_dat | Real data passed to f |
i_dat | Integer data passed to f |
x_epsilon | Used to test if current search interval is too small |
y_epsilon | Used to test if f is near zero |
max_itr | Maximum number of iterations before giving up |
status | Returns status of computation. 0 if everything worked. Range: 0 & 4001-4032. |
progress | Print progress as solver searches for a solution |
Definition at line 71 of file mrffl_solver_ne.f90.
References mrffl_config::mrfflik, and mrffl_config::mrfflrk.
Referenced by multi_bisection().
subroutine, public mrffl_solver_ne::multi_bisection | ( | real(kind=rk), intent(out) | xc, |
real(kind=rk), dimension(:), intent(in) | x0_init, | ||
real(kind=rk), dimension(:), intent(in) | x1_init, | ||
procedure(func_to_solve_t) | f, | ||
real(kind=rk), dimension(:), intent(in) | r_dat, | ||
integer(kind=ik), dimension(:), intent(in) | i_dat, | ||
real(kind=rk), intent(in) | x_epsilon, | ||
real(kind=rk), intent(in) | y_epsilon, | ||
integer(kind=ik), intent(in) | max_itr, | ||
integer(kind=ik), intent(out) | status, | ||
logical, intent(in) | progress ) |
Use bisection() to search for a root for the function f in a list of intervals returning the first root found.
xc | The solution (or last value tested if no solution is found) |
x0_init | A VECTOR of left sides for search intervals |
x1_init | A VECTOR of right sides for search intervals |
f | Function to solve for zero |
r_dat | Real data passed to f |
i_dat | Integer data passed to f |
x_epsilon | Used to test if current search interval is too small |
y_epsilon | Used to test if f is near zero |
max_itr | Maximum number of iterations before giving up |
status | Returns status of computation. 0 if everything worked. Range: 0 & 4033-4064. |
progress | Print progress as solver searches for a solution |
Definition at line 163 of file mrffl_solver_ne.f90.
References bisection(), mrffl_config::mrfflik, and mrffl_config::mrfflrk.