Skip to content

Commit 2028067

Browse files
committed
renamed anderson_bjorck_king to anderson_bjorck_kroger (abkk)
updates to test
1 parent fabc6df commit 2028067

File tree

3 files changed

+77
-73
lines changed

3 files changed

+77
-73
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Procedure | Description | Reference
7272
[`illinois`](https://jacobwilliams.github.io/roots-fortran/proc/illinois.html) | Illinois method | [Dowell & Jarratt (1971)](https://personal.math.ubc.ca/~loew/mech2/Dowell+Jarratt.pdf)
7373
[`pegasus`](https://jacobwilliams.github.io/roots-fortran/proc/pegasus.html) | Pegasus method | [Dowell & Jarratt (1972)](https://link.springer.com/article/10.1007/BF01932959)
7474
[`anderson_bjorck`](https://jacobwilliams.github.io/roots-fortran/proc/anderson_bjorck.html) | Anderson-Bjorck method | [King (1973)](https://link.springer.com/article/10.1007/BF01933405)
75-
[`anderson_bjorck_king`](https://jacobwilliams.github.io/roots-fortran/proc/anderson_bjorck_king.html) | A [variant](https://link.springer.com/content/pdf/bbm%3A978-3-642-05175-3%2F1.pdf) of `anderson_bjorck` | [King (1973)](https://link.springer.com/article/10.1007/BF01933405)
75+
[`abkk`](https://jacobwilliams.github.io/roots-fortran/proc/abkk.html) | A [variant](https://link.springer.com/content/pdf/bbm%3A978-3-642-05175-3%2F1.pdf) of `anderson_bjorck` | [King (1973)](https://link.springer.com/article/10.1007/BF01933405)
7676
[`ridders`](https://jacobwilliams.github.io/roots-fortran/proc/ridders.html) | Classic Ridders method | [Ridders (1979)](https://cs.fit.edu/~dmitra/SciComp/Resources/RidderMethod.pdf)
7777
[`toms748`](https://jacobwilliams.github.io/roots-fortran/proc/toms748.html) | Algorithm 748 | [Alefeld, Potra, Shi (1995)](https://dl.acm.org/doi/abs/10.1145/210089.210111)
7878
[`chandrupatla`](https://jacobwilliams.github.io/roots-fortran/proc/chandrupatla.html) | Hybrid quadratic/bisection algorithm | [Chandrupatla (1997)](https://dl.acm.org/doi/10.1016/S0965-9978%2896%2900051-8)
@@ -87,7 +87,7 @@ Procedure | Description | Reference
8787
In general, all the methods are guaranteed to converge. Some will be more efficient (in terms of number of function evaluations) than others for various problems. The methods can be broadly classified into three groups:
8888

8989
* Simple classical methods (`bisection`, `regula_falsi`, `illinois`, `ridders`).
90-
* Newfangled methods (`zhang`, `barycentric`, `blendtf`, `bdqrf`, `anderson_bjorck_king`, `rbp`). These rarely or ever seem to be better than the best methods.
90+
* Newfangled methods (`zhang`, `barycentric`, `blendtf`, `bdqrf`, `abkk`, `rbp`). These rarely or ever seem to be better than the best methods.
9191
* Best methods (`anderson_bjorck`, `muller`, `pegasus`, `toms748`, `brent`, `brentq`, `brenth`, `chandrupatla`, `itp`). Generally, one of these will be the most efficient method.
9292

9393
Note that some of the implementations in this library contain additional checks for robustness, and so may behave better than naive implementations of the same algorithms. In addition, all methods have an option to fall back to bisection if the method fails to converge.

src/root_module.F90

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ module root_module
6565
type(root_method),parameter,public :: root_method_chandrupatla = root_method(12, 'chandrupatla') !! enum type for `chandrupatla` method
6666
type(root_method),parameter,public :: root_method_toms748 = root_method(13, 'toms748') !! enum type for `toms748` method
6767
type(root_method),parameter,public :: root_method_zhang = root_method(14, 'zhang') !! enum type for `zhang` method
68-
type(root_method),parameter,public :: root_method_anderson_bjorck_king = root_method(15, 'anderson_bjorck_king') !! enum type for `anderson_bjorck_king` method
68+
type(root_method),parameter,public :: root_method_anderson_bjorck_kroger = root_method(15, 'abkk') !! enum type for `anderson_bjorck_kroger` method
6969
type(root_method),parameter,public :: root_method_blendtf = root_method(16, 'blendtf') !! enum type for `blendtf` method
7070
type(root_method),parameter,public :: root_method_barycentric = root_method(17, 'barycentric') !! enum type for `barycentric` method
7171
type(root_method),parameter,public :: root_method_itp = root_method(18, 'itp') !! enum type for `itp` method
@@ -87,7 +87,7 @@ module root_module
8787
root_method_chandrupatla, &
8888
root_method_toms748, &
8989
root_method_zhang, &
90-
root_method_anderson_bjorck_king, &
90+
root_method_anderson_bjorck_kroger, &
9191
root_method_blendtf, &
9292
root_method_barycentric, &
9393
root_method_itp, &
@@ -227,13 +227,13 @@ module root_module
227227
procedure,public :: find_root => zhang
228228
end type zhang_solver
229229

230-
type,extends(root_solver),public :: anderson_bjorck_king_solver
231-
!! anderson-bjorck-king root solver
230+
type,extends(root_solver),public :: anderson_bjorck_kroger_solver
231+
!! modified anderson-bjorck-king root solver
232232
private
233233
contains
234234
private
235-
procedure,public :: find_root => anderson_bjorck_king
236-
end type anderson_bjorck_king_solver
235+
procedure,public :: find_root => anderson_bjorck_kroger
236+
end type anderson_bjorck_kroger_solver
237237

238238
type,extends(root_solver),public :: blendtf_solver
239239
!! blendtf root solver
@@ -473,7 +473,7 @@ subroutine root_scalar_by_type(method,fun,ax,bx,xzero,fzero,iflag,&
473473
case(root_method_chandrupatla%id); allocate(chandrupatla_solver :: s)
474474
case(root_method_toms748%id); allocate(toms748_solver :: s)
475475
case(root_method_zhang%id); allocate(zhang_solver :: s)
476-
case(root_method_anderson_bjorck_king%id); allocate(anderson_bjorck_king_solver :: s)
476+
case(root_method_anderson_bjorck_kroger%id); allocate(anderson_bjorck_kroger_solver :: s)
477477
case(root_method_blendtf%id); allocate(blendtf_solver :: s)
478478
case(root_method_barycentric%id); allocate(barycentric_solver :: s)
479479
case(root_method_itp%id); allocate(itp_solver :: s)
@@ -2133,16 +2133,16 @@ end subroutine zhang
21332133
! an extra initial bisection step.
21342134
!
21352135
!### See also
2136-
! * Kroger & Torsten, "On-Line Trajectory Generation in Robotic Systems", 2010.
2136+
! * Torsten Kroger, "On-Line Trajectory Generation in Robotic Systems", 2010.
21372137
! https://link.springer.com/content/pdf/bbm%3A978-3-642-05175-3%2F1.pdf
21382138
!
2139-
!@note Really, should name this something else.
2139+
!@note This was originally called `anderson_bjorck_king` but that was a misnomer.
21402140

2141-
subroutine anderson_bjorck_king(me,ax,bx,fax,fbx,xzero,fzero,iflag)
2141+
subroutine anderson_bjorck_kroger(me,ax,bx,fax,fbx,xzero,fzero,iflag)
21422142

21432143
implicit none
21442144

2145-
class(anderson_bjorck_king_solver),intent(inout) :: me
2145+
class(anderson_bjorck_kroger_solver),intent(inout) :: me
21462146
real(wp),intent(in) :: ax !! left endpoint of initial interval
21472147
real(wp),intent(in) :: bx !! right endpoint of initial interval
21482148
real(wp),intent(in) :: fax !! `f(ax)`
@@ -2220,7 +2220,7 @@ subroutine anderson_bjorck_king(me,ax,bx,fax,fbx,xzero,fzero,iflag)
22202220

22212221
end do
22222222

2223-
end subroutine anderson_bjorck_king
2223+
end subroutine anderson_bjorck_kroger
22242224
!*****************************************************************************************
22252225

22262226
!*****************************************************************************************

test/root_tests.f90

Lines changed: 63 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,26 @@ program root_tests
4141

4242
integer,parameter :: number_of_methods = 20 !! number of methods to test
4343
character(len=100),dimension(number_of_methods),parameter :: methods = [ &
44-
'barycentric ', &
45-
'anderson_bjorck_king', &
46-
'zhang ', &
47-
'bisection ', &
48-
'regula_falsi ', &
49-
'illinois ', &
50-
'ridders ', &
51-
'blendtf ', &
52-
'bdqrf ', &
53-
'rbp ', &
54-
'itp ', &
55-
'modab ', &
56-
'pegasus ', &
57-
'muller ', &
58-
'chandrupatla ', &
59-
'anderson_bjorck ', &
60-
'brent ', &
61-
'toms748 ', &
62-
'brentq ', &
63-
'brenth ' ] !! method names - the order here is roughly the order of worst to best (see the root report output file).
44+
'bisection ', &
45+
'regula_falsi ', &
46+
'abkk ', &
47+
'barycentric ', &
48+
'zhang ', &
49+
'ridders ', &
50+
'illinois ', &
51+
'blendtf ', &
52+
'itp ', &
53+
'bdqrf ', &
54+
'rbp ', &
55+
'modab ', &
56+
'pegasus ', &
57+
'toms748 ', &
58+
'brent ', &
59+
'brentq ', &
60+
'anderson_bjorck ', &
61+
'brenth ', &
62+
'muller ', &
63+
'chandrupatla ' ] !! method names - the order here is roughly the order of worst to best (see the root report output file). - but with bis and rf as the first wo
6464

6565
integer,dimension(number_of_methods) :: number_of_wins, ivec, number_of_failures, ivec2
6666

@@ -514,28 +514,46 @@ subroutine problems(x, ax, bx, fx, xroot, cases, num_of_problems, latex, bounds,
514514
end if
515515
if (present(latex)) latex = '-2 \sum_{i=1}^{20} ((2i - 5)^2)/(x - i^2)^3'
516516

517-
!.... 13 & 14 don't actually converge to the right root with real64 since the func value is lower than the tol on the bound....
518517
case (12)
518+
!.... some of these don't actually converge to the right root with
519+
! real64 since the func value is lower than the tol on the bound....
519520
a = -9.0_wp
520521
b = 31.0_wp
521522
root = 0.0_wp
522-
if (present(x)) f = -40.0_wp*x*exp(-1.0_wp*x)
523-
if (present(latex)) latex = '-40 x \mathrm{e}^{-x}'
524-
if (present(bounds)) bounds = '-9,31'
525-
case (13)
526-
a = -9.0_wp
527-
b = 31.0_wp
528-
root = 0.0_wp
529-
if (present(x)) f = -100.0_wp*x*exp(-2.0_wp*x)
530-
if (present(latex)) latex = '-100 x \mathrm{e}^{-2 x}'
531-
if (present(bounds)) bounds = '-9,31'
532-
case (14)
533-
a = -9.0_wp
534-
b = 31.0_wp
535-
root = 0.0_wp
536-
if (present(x)) f = -200.0_wp*x*exp(-3.0_wp*x)
537-
if (present(latex)) latex = '-200 x \mathrm{e}^{-3 x}'
523+
ns = [40,100,200]
524+
525+
if (present(x)) f = -n*x*exp(-1.0_wp*x)
526+
if (present(latex)) latex = '-n x \mathrm{e}^{-x}'
538527
if (present(bounds)) bounds = '-9,31'
528+
! case (13)
529+
! a = -9.0_wp
530+
! b = 31.0_wp
531+
! root = 0.0_wp
532+
! if (present(x)) f = -100.0_wp*x*exp(-2.0_wp*x)
533+
! if (present(latex)) latex = '-100 x \mathrm{e}^{-2 x}'
534+
! if (present(bounds)) bounds = '-9,31'
535+
! case (14)
536+
! a = -9.0_wp
537+
! b = 31.0_wp
538+
! root = 0.0_wp
539+
! if (present(x)) f = -200.0_wp*x*exp(-3.0_wp*x)
540+
! if (present(latex)) latex = '-200 x \mathrm{e}^{-3 x}'
541+
! if (present(bounds)) bounds = '-9,31'
542+
543+
case(13)
544+
a = -3.0_wp
545+
b = 2.0_wp
546+
root = -2.1038034027355365E+00_wp
547+
if (present(x)) f = x**3 - 2.0_wp*x - x + 3.0_wp
548+
if (present(latex)) latex = 'x^3 - 2x - x + 3'
549+
if (present(bounds)) bounds = '-3,2'
550+
case(14)
551+
a = 0.0_wp
552+
b = 2.0_wp
553+
root = 3.5446310437502532E-01_wp
554+
if (present(x)) f = exp(-x) - x - sin(x)
555+
if (present(latex)) latex = 'e^{-x} - x - \sin(x)'
556+
if (present(bounds)) bounds = '0,2'
539557

540558
case (15)
541559
a = 0.0_wp
@@ -621,7 +639,7 @@ subroutine problems(x, ax, bx, fx, xroot, cases, num_of_problems, latex, bounds,
621639
if (present(bounds)) bounds = '0,1'
622640
case (21)
623641
a = 0.0_wp
624-
b = 1.0_wp
642+
b = 1.01_wp
625643
ns = [2,5,10,15,20]
626644
if (present(xroot)) then
627645
select case (n)
@@ -635,7 +653,7 @@ subroutine problems(x, ax, bx, fx, xroot, cases, num_of_problems, latex, bounds,
635653
end if
636654
if (present(x)) f = x**2 - (1.0_wp - x)**n
637655
if (present(latex)) latex = 'x^2 - (1-x)^n'
638-
if (present(bounds)) bounds = '0,1'
656+
if (present(bounds)) bounds = '0,1.01'
639657
case (22)
640658
a = 0.0_wp
641659
b = 1.0_wp
@@ -883,12 +901,12 @@ subroutine problems(x, ax, bx, fx, xroot, cases, num_of_problems, latex, bounds,
883901
if (present(bounds)) bounds = '-2,3'
884902
case (42)
885903
!From: http://www.mth.pdx.edu/~daescu/mth451_551/Muller_bisection.pdf
886-
a = 0.0_wp ! x1 is the location of the root for this case
887-
b = 3.0_wp
904+
a = -0.001_wp ! x1 is close to the location of the root for this case - changed bound from 0,3 to this
905+
b = 1.0_wp
888906
root = 0.0_wp
889907
if (present(x)) f = exp(x) - 2.0_wp*x - 1.0_wp
890908
if (present(latex)) latex = '\mathrm{e}^{x} - 2 x - 1'
891-
if (present(bounds)) bounds = '0,3'
909+
if (present(bounds)) bounds = '-0.001,1'
892910
case (43)
893911
a = 0.0_wp
894912
b = 0.7_wp
@@ -1752,12 +1770,12 @@ subroutine problems(x, ax, bx, fx, xroot, cases, num_of_problems, latex, bounds,
17521770
! http://sergiogaldino.pbworks.com/w/file/fetch/66011429/0130-1943543
17531771
! see: Root-test-functions.pdf : https://www.researchgate.net/publication/373922895_Additional_test_functions
17541772
case(146)
1755-
a = 0.5_wp
1773+
a = 0.51_wp ! change bounds from .5,1.5 so first bisection isn't the root
17561774
b = 1.5_wp
17571775
root = 1.0E+00_wp
17581776
if (present(x)) f = x**3 - 1.0_wp
17591777
if (present(latex)) latex = 'x^3 - 1'
1760-
if (present(bounds)) bounds = '0.5,1.5'
1778+
if (present(bounds)) bounds = '0.51,1.5'
17611779
case(147)
17621780
a = 0.1_wp
17631781
b = 1.0_wp
@@ -1838,28 +1856,14 @@ subroutine problems(x, ax, bx, fx, xroot, cases, num_of_problems, latex, bounds,
18381856
if (present(x)) f = (x**2 - x - 6.0_wp) * (x**2 - 3.0_wp * x + 2.0_wp)
18391857
if (present(latex)) latex = '(x^2 - x - 6)(x^2 - 3x + 2)'
18401858

1841-
case(158)
1842-
a = -3.0_wp
1843-
b = 2.0_wp
1844-
root = -2.1038034027355365E+00_wp
1845-
if (present(x)) f = x**3 - 2.0_wp*x - x + 3.0_wp
1846-
if (present(latex)) latex = 'x^3 - 2x - x + 3'
1847-
if (present(bounds)) bounds = '-3,2'
1848-
case(159)
1849-
a = 0.0_wp
1850-
b = 2.0_wp
1851-
root = 3.5446310437502532E-01_wp
1852-
if (present(x)) f = exp(-x) - x - sin(x)
1853-
if (present(latex)) latex = 'e^{-x} - x - \sin(x)'
1854-
if (present(bounds)) bounds = '0,2'
18551859

18561860

18571861
case default
18581862
write(*,*) 'invalid case: ', nprob
18591863
error stop 'invalid case'
18601864
end select
18611865

1862-
if (present(num_of_problems)) num_of_problems = 159
1866+
if (present(num_of_problems)) num_of_problems = 157
18631867

18641868
! outputs:
18651869
if (present(ax)) ax = a

0 commit comments

Comments
 (0)