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.
Functions.interpolate(x, tuples); // jlo = 1 Functions.interpolate(x, tuples, jlo);
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.
interpolate(1.5, {{0,1},{1,2}, {2,4},{3,5}}); // (3.0, 2)
encapsulated function interpolate
import BusinessSimulation.Icons.Function;
import BusinessSimulation.Functions.{rawInterpolate,hunt,locate};
extends Function;
input Real x "Value to locate in a list";
input Real[:, 2] tuples "Ordered list of values";
input Integer jlo = 1 "Index start value for the search";
output Real y "Interpolated value";
output Integer jsav "Index value used for the current interpolation";
end interpolate;