functionhunt
Find left index in an ordered list of value given a start index value
Extends from Function ((Weighted) geometric mean).
Information
This information is part of the Business Simulation Library (BSL). Please support this work and ► donate.
The output res is an index value for the ordered (either ascending or descending) list xVals so that for any x with min(xVals) <= max(xVals) the condition xVals[res] <= x <= xVals[res+1].
Syntax
Functions.hunt(x, {x1, x2, x3, ... xn}); // jsav = 1
Functions.hunt(x, {x1, x2, x3, ... xn}, jsav);
Implementation
The implementation closely follows that given in Press et al. [26, pp. 115-117]
Examples
hunt(1.9, {0,1,2,3,4}, 1); // 2
hunt(2.5, {3,2,1,0}, 1); // 1
See also
Inputs
| Type | Name | Default | Description |
|---|---|---|---|
| Real | x (from geometricMean) | Vector input | |
| Real | weights (from geometricMean) | ones(size(x, 1)) | Vector of weights |
| Real | xVals | Ordered list of values | |
| Integer | jsav | 1 | Start index value for the search |
Outputs
| Type | Name | Default | Description |
|---|---|---|---|
| Real | y (from geometricMean) | ||
| Integer | res | Index for the list so that xVals[res] <= x <= xVals[res+1] |
Revisions
- Introduced in v2.1.0.