.BusinessSimulation.Functions.locate

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.locate(x, {x1, x2, x3, ... xn});

Implementation

The implementation closely follows that given in Press et al. [26, pp. 114f.]

Examples


locate(1.9, {0,1,2,3,4}); // 2
locate(2.5, {3,2,1,0});   // 1

See also

hunt

Interface

encapsulated function locate
  import BusinessSimulation.Icons.Function;
  import BusinessSimulation.Functions.bitShiftRight;
  extends Function;
  input Real x "Value to locate in a list";
  input Real[:] xVals "Ordered list of values";
  output Integer res "Index for the list so that xVals[res] <= x <= xVals[res+1]";
end locate;

Revisions


Generated at 2024-11-23T19:25:52Z by OpenModelicaOpenModelica 1.24.2 using GenerateDoc.mos