.BusinessSimulation.Functions.geometricMean

Information

This information is part of the Business Simulation Library (BSL). Please support this work and ► donate.

The output y is the geometric mean of the components of the input vector x. As a second argument a vector of positive weights (default = 1 for each weight) can be given to calculate the weighted geometric mean.

Syntax

Functions.geometricMean(x);
Functions.geometricMean(x, weights);

Implementation


  w := BusinessSimulation.Functions.clip(weights, {0, inf});
  y := if min(x) < small then 0 else exp( sum( log(x[i]) * w[i] for i in 1:n ) / sum(w) );

Notes

Examples


Functions.geometricMean({10, 20});        // 14.1421..
Functions.geometricMean({ 0, 20});        //  0.0
Functions.geometricMean({10, 20},{1,10}); // 18.7786..
Functions.geometricMean({10, 20},{1,-1}); // 10.

See also

GeometricMean, arithmeticMean

Interface

function geometricMean
  import BusinessSimulation.Constants.{inf,small};
  extends BusinessSimulation.Icons.Function;
  input Real[:] x "Vector input";
  input Real[size(x, 1)] weights = ones(size(x, 1)) "Vector of weights";
  output Real y;
end geometricMean;

Generated at 2024-04-28T18:16:21Z by OpenModelicaOpenModelica 1.22.3 using GenerateDoc.mos