WebCab Functions Web Services for .NET v2.0

Interpolation.BisectionLocate Method 

This is a utility function which searches an monotonic sequence (with increasing or decreasing elements) using the bisection method and returns the relative position within the sequence.

public int BisectionLocate(
   double[] monotonicSequence,
   double valueBeingOrdered
);

Parameters

monotonicSequence
An array of monotonic values which may be increasing or decreasing.
valueBeingOrdered
The point (or value) for which its order is being evaluated.

Remarks

We offer this method as an auxiliary method since though sorting algorithms are strictly speaking not part of Interpolation or Extrapolation theory these methods are often required such methods. Here we implement what is known as the bisection method which will find the right place in about log2 n tries, where n is the number of elements in the monotonic sequence. To summaries the bisection algorithm is an ideal sorting algorithm to use here and can only marginally be improved in particular cases and most importantly it is sufficiently fast in all practical instances which we have encountered.

This method attempts to bracket the valueBeingOrdered parameter between two consecutive elements of the array and return the lower bound. Several special cases are treated separately as follows:

Exceptions

Exception TypeCondition
InterpolationExceptionThrown when the array is null.

See Also

Interpolation Class | Interpolation Namespace