FCSys.Utilities.Means

Package of mathematical mean functions

Information

Extends from Modelica.Icons.Package (Icon for standard packages).

Package Content

NameDescription
FCSys.Utilities.Means.arithmetic arithmetic Return the arithmetic mean of numbers
FCSys.Utilities.Means.harmonic harmonic Return the harmonic mean of numbers

FCSys.Utilities.Means.arithmetic FCSys.Utilities.Means.arithmetic

Return the arithmetic mean of numbers

Information

Example:
arithmetic({1,2,3}) returns 2.

Extends from Modelica.Icons.Function (Icon for functions).

Inputs

TypeNameDefaultDescription
Realu[:] Vector of numbers

Outputs

TypeNameDescription
RealmeanArithmetic mean

Modelica definition

function arithmetic "Return the arithmetic mean of numbers"
  extends Modelica.Icons.Function;
  input Real u[:] "Vector of numbers";
  output Real mean "Arithmetic mean";

algorithm 
  mean := sum(u)/size(u, 1);
end arithmetic;

FCSys.Utilities.Means.harmonic FCSys.Utilities.Means.harmonic

Return the harmonic mean of numbers

Information

Example:
harmonic({1,1/3}) returns 0.5.

Extends from Modelica.Icons.Function (Icon for functions).

Inputs

TypeNameDefaultDescription
Realu[:] Vector of numbers

Outputs

TypeNameDescription
RealmeanHarmonic mean

Modelica definition

function harmonic "Return the harmonic mean of numbers"
  extends Modelica.Icons.Function;
  input Real u[:] "Vector of numbers";
  output Real mean "Harmonic mean";

algorithm 
  mean := if size(u, 1) == 1 then u[1] else size(u, 1)/sum(1/u for u in u);
end harmonic;