38 PURE SUBROUTINE func(x,fx,plist)
41 REAL,
INTENT(IN),
DIMENSION(:),
OPTIONAL :: plist
42 REAL,
INTENT(OUT) :: fx
46 PURE SUBROUTINE funcd(x,fx,dfx,plist)
49 REAL,
INTENT(IN),
DIMENSION(:),
OPTIONAL :: plist
50 REAL,
INTENT(OUT) :: fx,dfx
55 INTEGER,
PARAMETER :: num_tests = 13
56 INTEGER,
PARAMETER :: num_methods = 8
57 CHARACTER(LEN=16),
PARAMETER,
DIMENSION(NUM_METHODS) :: method_name = (/ &
66 REAL,
PARAMETER,
DIMENSION(2,NUM_TESTS) :: bounds = reshape((/ 0.0, 1.2, &
80 DOUBLE PRECISION,
PARAMETER,
DIMENSION(NUM_TESTS) :: ref_roots = &
81 (/ 3.9942229171096819451d-01, 8.0413309750366432374d-01, 9.0340766319186021294d-01, &
82 7.7014241346192677110d-02, 2.5920449372984746773d-01, 5.3674166257799978186d-01, &
83 4.4754176206055907112d-01, 1.1111111111111111111d-01, 5.0000003403025908310d-01, &
84 6.7980892150470050192d-01, -3.5938136638046273022d-01, 1.6487212707001281468d-00, &
85 1.0000000000000000000d-00 &
88 REAL :: root, xm, dx_rel, dx_acc, plist(1)
89 INTEGER :: i,k, iter, error
90 CHARACTER(LEN=64) :: tap_message
91 LOGICAL :: verbose_results = .false.
94 WRITE (*,
"(A)")
"=========================================================" 95 WRITE (*,
"(A)")
" << Testing root finding algorithms >> " 96 WRITE (*,
"(A)")
"=========================================================" 99 tap_plan((num_methods-1)*num_tests)
108 xm = 0.5*(bounds(1,k)+bounds(2,k))
109 print
'(A,I2,A,2(ES10.2))',
"Test #",k,
" Search Interval: ",bounds(1,k),bounds(2,k)
110 print
'(A)',
"---------------------------------------------------------" 111 IF (verbose_results) print
'(A20,ES27.19)',
"reference result", ref_roots(k)
134 dx_rel = abs(1.0-root/ref_roots(k))
135 IF (verbose_results)
CALL printresults(method_name(i),root,ref_roots(k),error,iter)
144 WRITE (tap_message,
'(A16,A11,ES9.2,A3,ES9.2)') method_name(i),
": dx_rel = ", dx_rel,
" < ", dx_acc
145 tap_check(dx_rel.LE.dx_acc,tap_message)
149 print
'(A)',
"---------------------------------------------------------" 157 SUBROUTINE printresults(method,root,ref_root,error,iter)
159 CHARACTER(LEN=*),
INTENT(IN) :: method
160 REAL,
INTENT(IN) :: root
161 DOUBLE PRECISION,
INTENT(IN) :: ref_root
162 INTEGER,
INTENT(IN) :: error,iter
166 print
'(A20,ES23.15,ES9.1,I4)',trim(method),root,abs(1.0-root/ref_root),iter
190 PURE SUBROUTINE func(x,fx,plist)
193 REAL,
INTENT(IN) :: x
194 REAL,
INTENT(IN),
DIMENSION(:),
OPTIONAL :: plist
195 REAL,
INTENT(OUT) :: fx
199 fx = x*x*(x*x/3. + sqrt(2.)*sin(x)) - sqrt(3.)/18.
205 fx = 2*(x*exp(-9.)-exp(-9*x)) + 1.
209 fx = (x-1.)*exp(-9*x) + x**9
211 fx = x*x + sin(x/9.) - 0.25
215 fx = tan(x) - x - 0.0463025
217 fx = x*(x+sin(sqrt(75.)*x)) - 0.2
221 fx = log(x) + 0.5*x*x/exp(1.) -2*x/sqrt(exp(1.)) + 1.
228 PURE SUBROUTINE funcd(x,fx,dfx,plist)
231 REAL,
INTENT(IN) :: x
232 REAL,
INTENT(IN),
DIMENSION(:),
OPTIONAL :: plist
233 REAL,
INTENT(OUT) :: fx,dfx
237 fx = x*x*(x*x/3. + sqrt(2.)*sin(x)) - sqrt(3.)/18.
238 dfx= 2*x*(sqrt(2.)*sin(x)+x*x/3.)+x*x*(sqrt(2.)*cos(x)+(2*x)/3.)
244 dfx= 35*35*x**34 - 1.0
246 fx = 2*(x*exp(-9.)-exp(-9*x)) + 1.
247 dfx= 2*(9*exp(-9*x)+exp(-9.))
250 dfx= 2*x + 9*(1.-x)**8
252 fx = (x-1.)*exp(-9*x) + x**9
253 dfx= (10.-9*x)*exp(-9*x) + 9*x**8
255 fx = x*x + sin(x/9.) - 0.25
256 dfx= 2*x + cos(x/9.)/9.
261 fx = tan(x) - x - 0.0463025
262 dfx= 1./cos(x)**2 - 1.
264 fx = x*(x+sin(sqrt(75.)*x)) - 0.2
265 dfx= sin(sqrt(75.)*x) + x*(2. + sqrt(75.)*cos(sqrt(75.)*x))
270 fx = log(x) + 0.5*x*x/exp(1.) - 2*x/sqrt(exp(1.)) + 1.
271 dfx= 1./x + x/exp(1.) - 2./sqrt(exp(1.))
pure subroutine funcd(y, fy, dfy, plist)
subroutine, public getroot_newton(funcd, x1, x2, root, error, plist, xm, iterations)
subroutine, public getroot_pegasus(func, x1, x2, root, error, plist, xm, iterations)
subroutine, public getroot_bisection(func, x1, x2, root, error, plist, xm, iterations)
subroutine, public getroot_brentdekker(func, x1, x2, root, error, plist, xm, iterations)
subroutine printresults(method, root, ref_root, error, iter)
pure subroutine func(x, fx, plist)
subroutine, public getroot_andersonbjoerk(func, x1, x2, root, error, plist, xm, iterations)
real, parameter, public default_accuracy
subroutine, public getroot_regulafalsi(func, x1, x2, root, error, plist, xm, iterations)
subroutine, public getroot_ridder(func, x1, x2, root, error, plist, xm, iterations)
character(len=64) function, public geterrormessage(error)
subroutine, public getroot_king(func, x1, x2, root, error, plist, xm, iterations)