Function OrbitUtils::zbrak#
Defined in File numrecipes.cc
Function Documentation#
-
int OrbitUtils::zbrak(float (*fx)(float, float, float, float), float x1, float x2, int n, float *xb1, float *xb2, int &nb, float param1, float param2, float param3)#
Bracket subintervals where a function changes sign.
Scans the interval [x1, x2] by dividing it into
nequal subintervals and records subinterval endpoints where the functionfxchanges sign (i.e., a root is bracketed).The function
fxmust have the signature: float fx(float x, float p1, float p2, float p3); It is evaluated at the grid points x1, x1 + dx, x1 + 2*dx, …, x2, where dx = (x2 - x1) / n.When an interval [xb1[k], xb2[k]] is found such that fx(xb1[k]) and fx(xb2[k]) have opposite signs (fc*fp <= 0), the endpoints are stored in the output arrays xb1 and xb2 at the same index k (1-based indexing is used internally; the caller should account for this).
Note
The function uses sequential evaluations of
fxand treats a zero or a sign change (fc*fp <= 0.0) as a bracket. Adjacent subintervals that both satisfy this condition will each be reported.The implementation uses 1-based indexing internally when filling xb1/xb2. The caller should allocate arrays accordingly and interpret the filled entries consistent with the calling convention used in the surrounding code.
- Parameters
fx – Pointer to the function to examine. Signature: float fx(float x, float param1, float param2, float param3).
x1 – Left end of the search interval.
x2 – Right end of the search interval.
n – Number of equal subintervals to split [x1, x2] into.
xb1 – Output array to receive left endpoints of bracketing subintervals. Must be large enough to hold up to the capacity indicated by the integer referenced by
nb(seenbdescription).xb2 – Output array to receive right endpoints of bracketing subintervals. Same required capacity as
xb1.nb – Reference to an integer indicating the maximum number of bracket intervals the caller can accept on input; on return this integer is set to the actual number of brackets found (nb <= original nb).
param1 – First user parameter passed through to
fx.param2 – Second user parameter passed through to
fx.param3 – Third user parameter passed through to
fx.
- Returns
Returns 0 on completion. If the number of found brackets reaches the input capacity (nb), the function returns immediately with xb1/xb2 filled up to that capacity and nb set equal to that capacity.