functioninterpolate

Interpolate in an ordered list of tuples

Extends from Function (Icon for functions).

Information

This information is part of the Business Simulation Library (BSL). Please support this work and ► donate.

The output y is the interpolated value given a list of tuples (tuples = { {x1,y1}, {x2,y2}, ...}) and an index value jlo (default = 1) to guide the search. The function will also return the actual index value jsav used for the interpolation.

Syntax


Functions.interpolate(x, tuples);  // jlo = 1
Functions.interpolate(x, tuples, jlo);

Implementation

The index value jlo is used to guide the further procedure: If jlo == 1 then we assume that we are starting out a fresh search und accordingly locate() is used to come up with the correct index value to use for rawInterpolate().

If jlo > 1, then we assume to already have searched in the list of tuples and we can use the last index value to speed up the search; accordingly hunt will be used to find the new index value.

Examples


interpolate(1.5, {{0,1},{1,2}, {2,4},{3,5}}); // (3.0, 2)

See also

rawInterpolate, locate, hunt

Inputs

TypeNameDefaultDescription
RealxValue to locate in a list
RealtuplesOrdered list of values
Integerjlo1Index start value for the search

Outputs

TypeNameDefaultDescription
RealyInterpolated value
IntegerjsavIndex value used for the current interpolation

Revisions

  • Introduced in v2.1.0.