Optimization::RootBrent Function

Overload List

#SignatureDescription
1int RootBrent(double ax, double bx, TRealFunction Func, const TMtxFloatPrecision FloatPrecision, const DewArray<double> &Consts, const DewArray<tObject *> &ObjConst, double &RootX, TOptStopReason &StopReason, int MaxIter, double Accuracy = 0, tStrings *Verbose = null);Finds a root (zero) of a single variable function.
2int RootBrent(double ax, double bx, TRealFunction Func, const TMtxFloatPrecision FloatPrecision, const DewArray<double> &Consts, const DewArray<tObject *> &ObjConst, double &RootX, TOptStopReason &StopReason);Finds a root of single variable function by using default settings and no log.

Overload 1: int RootBrent(double ax, double bx, TRealFunction Func, const TMtxFloatPrecision FloatPrecision, const DewArray<double> &Consts, const DewArray<tObject *> &ObjConst, double &RootX, TOptStopReason &StopReason, int MaxIter, double Accuracy = 0, tStrings *Verbose = null);

Finds a root (zero) of a single variable function.

#NameTypeDescription
1axdoubleDefines the lower end of the bracket enclosing the root.
2bxdoubleDefines the upper end of the bracket enclosing the root.
3FuncTRealFunctionReal function of single variable (must be of TRealFunction type) whose root is to be found. The function must return the SIGNED value f(x) and not its absolute value: the algorithm locates the sign change.
4FloatPrecisionconst TMtxFloatPrecisionSpecifies the floating point precision to be used by the routine.
5Constsconst DewArray<double> &Additional Func constant parameters (can be/is usually nil).
6ObjConstconst DewArray<tObject *> &Additional Func constant parameters (can be/is usually nil).
7RootXdouble &Returns the position of the function root. Returns NAN, if no root was bracketed.
8StopReasonTOptStopReason &Returns the reason why the root search stopped (see TOptStopReason).
9MaxIterintMaximum allowed numer of root search iterations.
10Accuracy = 0doubleDesired root position tolerance. Pass zero to iterate to full machine precision.
11Verbose = nulltStrings *If assigned, stores Func, evaluated at each iteration step. Optionally, you can also pass TOptControl object to the Verbose parameter. This allows the root search to be interrupted from another thread and optionally also allows logging and iteration count monitoring.

Returns: the number of iterations required to reach the solution(root) within given tolerance.

Remarks:

What it computes. Locates a root x^* of a real function of
one variable on the bracket [a_x,b_x] using Brent's method (the algol-60 zeroin: inverse quadratic interpolation and the secant rule, each step guarded by bisection). For the example objective

f(x) = x^3 - 2x - 5

Domain. a_x,b_x are finite reals; if b_x < a_x they are
swapped internally, so the order of the bracket does not matter. Func must change sign across the bracket, that is f(a_x) * f(b_x) <= 0. MaxIter > 0 caps the iterations; Accuracy ≥ 0 is the desired position tolerance.

Defined behaviour. Returns the iteration count and writes the root
to RootX. The convergence floor is 2 epsilon |x| + Accuracy/2, so Accuracy = 0 iterates to full machine precision - unlike Optimization::MinBrent, whose floor is sqrt(epsilon) |x| because a smooth minimum is numerically flat within that distance and a sign change is not. StopReason is TOptStopReason::OptResConverged when the bracket shrank below the tolerance or the function returned an exact zero, TOptStopReason::OptResNotFound when Func does not change sign across the bracket (no root is enclosed, and RootX is NAN),

TOptStopReason::OptResMaxIter when the iteration cap was hit,
TOptStopReason::optNANValue if the objective returned NaN, and
TOptStopReason::optStopped if the search was interrupted through
TOptControl. No exception is raised for a missing bracket: the

result is reported through StopReason.

Finds the root of a function of one variable. This routine uses a slightly modified version of the algol 60 procedure zero, introduced by Richard Brent.

See Also: TRealFunction, Optimization::MinBrent
Declared in Dew::Math::Units::Optimization · Dew.Math/Units.Optimization.h · Cross-compiler

Overload 2: int RootBrent(double ax, double bx, TRealFunction Func, const TMtxFloatPrecision FloatPrecision, const DewArray<double> &Consts, const DewArray<tObject *> &ObjConst, double &RootX, TOptStopReason &StopReason);

Finds a root of single variable function by using default settings and no log.

#NameTypeDescription
1axdouble
2bxdouble
3FuncTRealFunction
4FloatPrecisionconst TMtxFloatPrecision
5Constsconst DewArray<double> &
6ObjConstconst DewArray<tObject *> &
7RootXdouble &
8StopReasonTOptStopReason &
Remarks:

Use this version if algorithm step logs are not needed.

Declared in Dew::Math::Units::Optimization · Dew.Math/Units.Optimization.h · Cross-compiler