Overload List
| # | Signature | Description |
|---|---|---|
| 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. |
| 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. |
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.
| # | Name | Type | Description |
|---|---|---|---|
| 1 | ax | double | Defines the lower end of the bracket enclosing the root. |
| 2 | bx | double | Defines the upper end of the bracket enclosing the root. |
| 3 | Func | TRealFunction | Real 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. |
| 4 | FloatPrecision | const TMtxFloatPrecision | Specifies the floating point precision to be used by the routine. |
| 5 | Consts | const DewArray<double> & | Additional Func constant parameters (can be/is usually nil). |
| 6 | ObjConst | const DewArray<tObject *> & | Additional Func constant parameters (can be/is usually nil). |
| 7 | RootX | double & | Returns the position of the function root. Returns NAN, if no root was bracketed. |
| 8 | StopReason | TOptStopReason & | Returns the reason why the root search stopped (see TOptStopReason). |
| 9 | MaxIter | int | Maximum allowed numer of root search iterations. |
| 10 | Accuracy = 0 | double | Desired root position tolerance. Pass zero to iterate to full machine precision. |
| 11 | Verbose = null | tStrings * | 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.
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.
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.
| # | Name | Type | Description |
|---|---|---|---|
| 1 | ax | double | |
| 2 | bx | double | |
| 3 | Func | TRealFunction | |
| 4 | FloatPrecision | const TMtxFloatPrecision | |
| 5 | Consts | const DewArray<double> & | |
| 6 | ObjConst | const DewArray<tObject *> & | |
| 7 | RootX | double & | |
| 8 | StopReason | TOptStopReason & |
Use this version if algorithm step logs are not needed.