|
1 | 1 | /++ |
2 | 2 | Base numeric algorithms. |
3 | 3 |
|
| 4 | +Reworked part of `std.numeric`. |
| 5 | +
|
4 | 6 | License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0). |
5 | | -Authors: Ilya Yaroshenko, Don Clugston |
| 7 | +Authors: Ilya Yaroshenko (findLocalMin), Don Clugston (findRoot) |
6 | 8 | +/ |
7 | 9 | module mir.numeric; |
8 | 10 |
|
@@ -98,55 +100,46 @@ nothrow: |
98 | 100 | } |
99 | 101 | } |
100 | 102 |
|
101 | | -/** Find root of a real function f(x) by bracketing, allowing the |
102 | | - * termination condition to be specified. |
103 | | - * |
104 | | - * Given a function `f` and a range `[a .. b]` such that `f(a)` |
105 | | - * and `f(b)` have opposite signs or at least one of them equals ±0, |
106 | | - * returns the value of `x` in |
107 | | - * the range which is closest to a root of `f(x)`. If `f(x)` |
108 | | - * has more than one root in the range, one will be chosen |
109 | | - * arbitrarily. If `f(x)` returns NaN, NaN will be returned; |
110 | | - * otherwise, this algorithm is guaranteed to succeed. |
111 | | - * |
112 | | - * Uses an algorithm based on TOMS748, which uses inverse cubic |
113 | | - * interpolation whenever possible, otherwise reverting to parabolic |
114 | | - * or secant interpolation. Compared to TOMS748, this implementation |
115 | | - * improves worst-case performance by a factor of more than 100, and |
116 | | - * typical performance by a factor of 2. For 80-bit reals, most |
117 | | - * problems require 8 to 15 calls to `f(x)` to achieve full machine |
118 | | - * precision. The worst-case performance (pathological cases) is |
119 | | - * approximately twice the number of bits. |
120 | | - * |
121 | | - * References: "On Enclosing Simple Roots of Nonlinear Equations", |
122 | | - * G. Alefeld, F.A. Potra, Yixun Shi, Mathematics of Computation 61, |
123 | | - * pp733-744 (1993). Fortran code available from $(HTTP |
124 | | - * www.netlib.org,www.netlib.org) as algorithm TOMS478. |
125 | | - * |
126 | | - * Params: |
127 | | - * |
128 | | - * f = Function to be analyzed |
129 | | - * |
130 | | - * ax = Left bound of initial range of `f` known to contain the |
131 | | - * root. |
132 | | - * |
133 | | - * bx = Right bound of initial range of `f` known to contain the |
134 | | - * root. |
135 | | - * |
136 | | - * fax = Value of `f(ax)`. |
137 | | - * |
138 | | - * fbx = Value of `f(bx)`. `fax` and `fbx` should have opposite signs. |
139 | | - * (`f(ax)` and `f(bx)` are commonly known in advance.) |
140 | | - * |
141 | | - * |
142 | | - * tolerance = Defines an early termination condition. Receives the |
143 | | - * current upper and lower bounds on the root. The |
144 | | - * delegate must return `true` when these bounds are |
145 | | - * acceptable. If this function always returns `false`, |
146 | | - * full machine precision will be achieved. |
147 | | - * |
148 | | - * Returns: $(LREF FindRootResult) |
149 | | - */ |
| 103 | +/++ |
| 104 | +Find root of a real function f(x) by bracketing, allowing the |
| 105 | +termination condition to be specified. |
| 106 | +
|
| 107 | +Given a function `f` and a range `[a .. b]` such that `f(a)` |
| 108 | +and `f(b)` have opposite signs or at least one of them equals ±0, |
| 109 | +returns the value of `x` in |
| 110 | +the range which is closest to a root of `f(x)`. If `f(x)` |
| 111 | +has more than one root in the range, one will be chosen |
| 112 | +arbitrarily. If `f(x)` returns NaN, NaN will be returned; |
| 113 | +otherwise, this algorithm is guaranteed to succeed. |
| 114 | +
|
| 115 | +Uses an algorithm based on TOMS748, which uses inverse cubic |
| 116 | +interpolation whenever possible, otherwise reverting to parabolic |
| 117 | +or secant interpolation. Compared to TOMS748, this implementation |
| 118 | +improves worst-case performance by a factor of more than 100, and |
| 119 | +typical performance by a factor of 2. For 80-bit reals, most |
| 120 | +problems require 8 to 15 calls to `f(x)` to achieve full machine |
| 121 | +precision. The worst-case performance (pathological cases) is |
| 122 | +approximately twice the number of bits. |
| 123 | +
|
| 124 | +References: "On Enclosing Simple Roots of Nonlinear Equations", |
| 125 | +G. Alefeld, F.A. Potra, Yixun Shi, Mathematics of Computation 61, |
| 126 | +pp733-744 (1993). Fortran code available from $(HTTP |
| 127 | +www.netlib.org,www.netlib.org) as algorithm TOMS478. |
| 128 | +
|
| 129 | +Params: |
| 130 | +f = Function to be analyzed. `f(ax)` and `f(bx)` should have opposite signs. |
| 131 | +tolerance = tolerance = Defines an early termination condition. Receives the |
| 132 | + current upper and lower bounds on the root. The |
| 133 | + delegate must return `true` when these bounds are |
| 134 | + acceptable. If this function always returns `false` or |
| 135 | + it is null, full machine precision will be achieved. |
| 136 | +ax = Left bound of initial range of `f` known to contain the root. |
| 137 | +bx = Right bound of initial range of `f` known to contain the root. |
| 138 | +fax = Value of `f(ax)` (optional). |
| 139 | +fbx = Value of `f(bx)` (optional). |
| 140 | +
|
| 141 | +Returns: $(LREF FindRootResult) |
| 142 | ++/ |
150 | 143 | @fmamath |
151 | 144 | FindRootResult!T findRoot(alias f, alias tolerance = null, T)( |
152 | 145 | const T ax, |
|
0 commit comments