std.numeric.find_root
- multiple declarations
- Function findRoot
- Function findRoot
Function findRoot
Find a
real root of a
real function f
(x) via bracketing.
Given a
function
and f
a
range [
such that a
..b]
and f
(a
)
have opposite signs or at least one of them equals ±0,
returns the value of f
(b
)x
in
the range which is closest to a
root of
. 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.
f
(x)
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 to 15 calls to
to achieve full machine
precision. The worst-case performance (pathological cases) is
approximately twice the number of bits.
f
(x)
Prototypes
T findRoot(T, DF, DT)( DF f, T a, T b, DT tolerance ) if (isFloatingPoint!T && is(typeof(tolerance(T.init, T.init)) : bool) && is(typeof(f(T.init)) == R, R) && isFloatingPoint!R); T findRoot(T, DF)( DF f, T a, T b );
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.
Function findRoot
Find root of a
real function f
(x) by bracketing, allowing the
termination condition to be specified.
Prototypes
Tuple!(T,T,R,R) findRoot(T, R, DF, DT)( DF f, T ax, T bx, R fax, R fbx, DT tolerance ) if (isFloatingPoint!T && is(typeof(tolerance(T.init, T.init)) : bool) && is(typeof(f(T.init)) == R) && isFloatingPoint!R); Tuple!(T,T,R,R) findRoot(T, R, DF)( DF f, T ax, T bx, R fax, R fbx ); T findRoot(T, R)( R delegate(T) f, T a, T b, bool delegate(T lo, T hi) tolerance = );
Parameters
Name | Description |
---|---|
f | Function to be analyzed |
ax | Left bound of initial range of known to contain the
root.
|
bx | Right bound of initial range of known to contain the
root.
|
fax | Value of .
|
fbx | Value of . and should have opposite signs.
( and are commonly known in advance.)
|
tolerance | Defines an early termination condition. Receives the
current upper and lower bounds on the root. The
delegate must return true when these bounds are
acceptable. If this function always returns false ,
full machine precision will be achieved. |
Returns
A tuple consisting of two ranges. The first two elements are the
range (in x
) of the root, while the second pair of elements
are the corresponding function values at those points. If an exact
root was found, both of the first two elements will contain the
root, and the second pair of elements will be 0.
Authors
Andrei Alexandrescu, Don Clugston, Robert Jacques