50 real(
double),
intent(in) :: x1,x2,accur
51 integer,
intent(in),
optional :: verbose
52 integer,
intent(out),
optional :: status
55 real(
double),
external :: func
57 integer,
parameter :: max_iter = 100
58 real(
double),
parameter :: eps = epsilon(0.0_dbl)
60 integer :: iter,verbosity
61 real(
double) :: a,b,c,d,e, fa,fb,fc
62 real(
double) :: p,q,r,s, accur1,xm
64 if(
present(status)) status = 0
66 if(
present(verbose)) verbosity = verbose
77 if(fa*fb .gt. 0.0_dbl)
then
78 if(verbosity.gt.0)
write(0,
'(2(A,2ES12.3))')
' libSUFR - root_solver(): root is not bracketed by x1 and x2: ', &
81 if(
present(status)) status = 2
89 if(fb*fc.gt.0.0_dbl)
then
96 if(abs(fc).lt.abs(fb))
then
105 accur1 = 2*eps*abs(b) + 0.5_dbl*accur
108 if(abs(xm).le.accur1 .or.
deq(fb,0.0_dbl))
then
113 if(abs(e).ge.accur1 .and. abs(fa).gt.abs(fb))
then
121 p = s * ( 2*xm*q*(q-r) - (b-a)*(r-1.0_dbl) )
122 q = (q-1.0_dbl) * (r-1.0_dbl) * (s-1.0_dbl)
125 if(p.gt.0.0_dbl) q = -q
128 if(2*p .lt. min(3*xm*q-abs(accur1*q),abs(e*q)))
then
143 if(abs(d) .gt. accur1)
then
146 b = b + sign(accur1,xm)
154 if(verbosity.gt.0)
write(0,
'(A)')
' libSUFR - root_solver(): maximum number of iterations exceeded'
155 if(
present(status)) status = 1
188 real(
double),
intent(in) :: ax,bx,cx,accur
189 real(
double),
intent(out) :: xmin
190 integer,
intent(out),
optional :: status
191 integer,
intent(in),
optional :: verbose
193 real(
double),
external :: func
195 integer,
parameter :: max_iter = 100
196 real(
double),
parameter :: eps = epsilon(0.0_dbl)
198 integer :: iter,verbosity
199 real(
double) :: a,b,d,e,e1, p,q,r, accur1,accur2
200 real(
double) :: u,v,w,x,xm, fu,fv,fw,fx
203 if(
present(status)) status = 0
205 if(
present(verbose)) verbosity = verbose
229 if( abs(x-xm) .le. accur2 - 0.5_dbl*(b-a) )
then
236 if(abs(e).gt.accur1)
then
239 p = (x-v)*q - (x-w)*r
241 if(q.gt.0.0_dbl) p = -p
246 if(abs(p).ge.abs(0.5_dbl*q*e1) .or. p.le.q*(a-x) .or. p.ge.q*(b-x))
then
251 if(u-a.lt.accur2 .or. b-u.lt.accur2) d = sign(accur1,xm-x)
258 if(abs(d).ge.accur1)
then
261 u = x + sign(accur1,d)
289 if(fu.le.fw .or.
deq(w,x))
then
294 else if(fu.le.fv .or.
deq(v,x) .or.
deq(v,w))
then
304 if(verbosity.gt.0)
write(0,
'(A)')
' libSUFR - minimum_solver(): maximum number of iterations exceeded'
305 if(
present(status)) status = 1
338 real(
double),
intent(in) :: x1,x2, a1,a2
339 real(
double),
intent(out) :: y1,y2
340 real(
double),
parameter :: golden_ratio = 0.3819660_dbl
347 y1 = y2 * golden_ratio
Provides kinds and related constants/routines.
integer, parameter double
Double-precision float. Precision = 15, range = 307.
integer, parameter dbl
Double-precision float. Precision = 15, range = 307.
Procedures for numerical operations.
elemental logical function deq(x1, x2, eps)
Test whether two double-precision variables are equal to better than a given value (default: 2x machi...
Procedures to solve equations.
real(double) function root_solver(func, x1, x2, accur, status, verbose)
Using Brent's method, find the root of a function func that lies between x1 and x2.
real(double) function minimum_solver(func, ax, bx, cx, accur, xmin, status, verbose)
Use Brent's method and parabolic interpolation to find the minimum of function func that lies between...
pure subroutine golden_section(x1, x2, a1, a2, y1, y2)
Do a golden-section step for minimum_solver(): find the point that is a fraction 0....