65 subroutine bisection(xc, x0_init, x1_init, f, x_epsilon, y_epsilon, max_itr, status, progress)
68 real(kind=rk)
function func_to_solve_t(x)
71 real(kind=rk),
intent(in) :: x
72 end function func_to_solve_t
75 procedure(func_to_solve_t) :: f
76 real(kind=rk),
intent(out) :: xc
77 real(kind=rk),
intent(in) :: x0_init, x1_init
78 real(kind=rk),
intent(in) :: x_epsilon, y_epsilon
79 integer(kind=ik),
intent(in) :: max_itr
80 integer(kind=ik),
intent(out) :: status
81 logical,
intent(in) :: progress
82 real(kind=rk) :: x0, x1, f0, f1, fc
83 integer(kind=ik) :: itr
88 if (abs(f0) < y_epsilon)
then
94 if (abs(f1) < y_epsilon)
then
98 if (progress) print *, 0, x0, f0, x1, f1
99 if (((f0 < 0) .and. (f1 < 0)) .or. ((f0 > 0) .and. (f1 > 0)))
then
104 if (abs(x0-x1) < x_epsilon)
then
108 if (progress) print *, itr, x0, f0, x1, f1, xc, fc
109 if (abs(fc) < y_epsilon)
then
65 subroutine bisection(xc, x0_init, x1_init, f, x_epsilon, y_epsilon, max_itr, status, progress)
…
150 subroutine multi_bisection(xc, x0_init, x1_init, f, x_epsilon, y_epsilon, max_itr, status, progress)
154 real(kind=rk)
function func_to_solve_t(x)
157 real(kind=rk),
intent(in) :: x
158 end function func_to_solve_t
161 procedure(func_to_solve_t) :: f
162 real(kind=rk),
intent(out) :: xc
163 real(kind=rk),
intent(in) :: x0_init(:), x1_init(:)
164 real(kind=rk),
intent(in) :: x_epsilon, y_epsilon
165 integer(kind=ik),
intent(in) :: max_itr
166 integer(kind=ik),
intent(out) :: status
167 logical,
intent(in) :: progress
168 integer(kind=ik) :: interval, num_intervals
170 num_intervals =
size(x0_init, kind=ik)
171 do interval=1,num_intervals
172 if (progress) print *,
"Bisection on [", x0_init(interval),
", ", x1_init(interval),
"]"
173 call bisection(xc, x0_init(interval), x1_init(interval), f, x_epsilon, y_epsilon, max_itr, &
175 if (status == 0)
then
150 subroutine multi_bisection(xc, x0_init, x1_init, f, x_epsilon, y_epsilon, max_itr, status, progress)
…
Configuration for MRFFL (MR Fortran Finance Library).
integer, parameter, public mrfflrk
Real kind used in interfaces.
integer, parameter, public mrfflik
Integer kinds used in interfaces.
subroutine, public multi_bisection(xc, x0_init, x1_init, f, 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 ro...
subroutine, public bisection(xc, x0_init, x1_init, f, x_epsilon, y_epsilon, max_itr, status, progress)
Search for a root for the function f in the interval [x0_init, x1_init].