tango.math.Bracket

Algorithms for finding roots and extrema of one-argument real functions using bracketing.

License:

BSD style: see license.txt, Digital Mars.

Authors:

Don Clugston.
T findRoot(T, R)(scope R delegate(T) f, T ax, T bx) [public]
Find a real root of the real function f(x) via bracketing.
Given a range [a..b] such that f(a) and f(b) have opposite sign, returns the value of x in the range which is closest to a root of f(x). If f(x) has more than one root in the range, one will be chosen arbitrarily. If f(x) returns NaN, NaN will be returned; otherwise, this algorithm is guaranteed to succeed. Uses an algorithm based on TOMS748, which uses inverse cubic interpolation whenever possible, otherwise reverting to parabolic or secant interpolation. Compared to TOMS748, this implementation improves worst-case performance by a factor of more than 100, and typical performance by a factor of 2. For 80-bit reals, most problems require 8 - 15 calls to f(x) to achieve full machine precision. The worst-case performance (pathological cases) is approximately twice the number of bits.

References:

"On Enclosing Simple Roots of Nonlinear Equations", G. Alefeld, F.A. Potra, Yixun Shi, Mathematics of Computation 61, pp733-744 (1993). Fortran code available from www.netlib.org as algorithm TOMS478.
T findMinimum(T, R)(scope R delegate(T) func, T xlo, T xhi, T xinitial, out R funcMin) [public]
Find the minimum value of the function func().
Returns the value of x such that func(x) is minimised. Uses Brent's method, which uses a parabolic fit to rapidly approach the minimum but reverts to a Golden Section search where necessary.

The minimum is located to an accuracy of feqrel(min, truemin) < real.mant_dig/2.

Parameters:

func The function to be minimized xinitial Initial guess to be used. xlo, xhi Upper and lower bounds on x. func(xinitial) <= func(x1) and func(xinitial) <= func(x2) funcMin The minimum value of func(x).