.Modelica.Math.Vectors.find

Information

Syntax

Vectors.find(e, v);
Vectors.find(e, v, eps=0);

Description

The function call "Vectors.find(e, v)" returns the index of the first occurrence of input e in vector v. The test of equality is performed by "abs(e-v[i]) ≤ eps", where "eps" can be provided as third argument of the function. Default is "eps = 0".

Example

  Real v[3] = {1, 2, 3};
  Real e1 = 2;
  Real e2 = 3.01;
  Boolean result;
algorithm
  result := Vectors.find(e1,v);          // = 2
  result := Vectors.find(e2,v);          // = 0
  result := Vectors.find(e2,v,eps=0.1);  // = 3

See also

Vectors.isEqual

Interface

function find
  extends Modelica.Icons.Function;
  input Real e "Search for e";
  input Real v[:] "Real vector";
  input Real eps(min = 0) = 0 "Element e is equal to a element v[i] of vector v if abs(e-v[i]) <= eps";
  output Integer result "v[result] = e (first occurrence of e); result=0, if not found";
end find;

Generated at 2024-12-26T19:25:54Z by OpenModelicaOpenModelica 1.24.3 using GenerateDoc.mos