.Modelica.Math.Vectors.interpolate

Information

Syntax

// Real    x[:], y[:], xi, yi;
// Integer iLast, iNew;
        yi = Vectors.interpolate(x,y,xi);
(yi, iNew) = Vectors.interpolate(x,y,xi,iLast=1);

Description

The function call "Vectors.interpolate(x,y,xi)" interpolates linearly in vectors (x,y) and returns the value yi that corresponds to xi. Vector x[:] must consist of monotonically increasing values. If xi < x[1] or > x[end], then extrapolation takes places through the first or last two x[:] values, respectively. If the x and y vectors have length 1, then always y[1] is returned. The search for the interval x[iNew] ≤ xi < x[iNew+1] starts at the optional input argument "iLast". The index "iNew" is returned as output argument. The usage of "iLast" and "iNew" is useful to increase the efficiency of the call, if many interpolations take place. If x has two or more identical values then interpolation utilizes the x-value with the largest index.

Example

  Real x1[:] = { 0,  2,  4,  6,  8, 10};
  Real x2[:] = { 1,  2,  3,  3,  4,  5};
  Real y[:]  = {10, 20, 30, 40, 50, 60};
algorithm
  (yi, iNew) := Vectors.interpolate(x1,y,5);  // yi = 35, iNew=3
  (yi, iNew) := Vectors.interpolate(x2,y,4);  // yi = 50, iNew=5
  (yi, iNew) := Vectors.interpolate(x2,y,3);  // yi = 40, iNew=4

Interface

function interpolate
  extends Modelica.Icons.Function;
  input Real x[:] "Abscissa table vector (strict monotonically increasing values required)";
  input Real y[size(x, 1)] "Ordinate table vector";
  input Real xi "Desired abscissa value";
  input Integer iLast = 1 "Index used in last search";
  output Real yi "Ordinate value corresponding to xi";
  output Integer iNew = 1 "xi is in the interval x[iNew] <= xi < x[iNew+1]";
end interpolate;

Generated at 2020-06-05T07:38:22Z by OpenModelica 1.16.0~dev-420-gc007a39