Name | Description |
---|---|
arithmetic | Return the arithmetic mean of numbers |
harmonic | Return the harmonic mean of numbers |
Example:
arithmetic({1,2,3})
returns 2.
Type | Name | Default | Description |
---|---|---|---|
Real | u[:] | Vector of numbers |
Type | Name | Description |
---|---|---|
Real | mean | Arithmetic mean |
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;
Example:
harmonic({1,1/3})
returns 0.5.
Type | Name | Default | Description |
---|---|---|---|
Real | u[:] | Vector of numbers |
Type | Name | Description |
---|---|---|
Real | mean | Harmonic mean |
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;