functionarithmeticMean

(Weighted) arithmetic mean

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

Information

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

The output y is the arithmetic 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 arithmetic mean.

Syntax

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

Implementation


  w := BusinessSimulation.Functions.clip(weights, {0, inf});
  y := sum(x[i] * w[i] for i in 1:n) / sum(w);

Notes

  • Any negative weight will be set to zero in order to prevent negative weights.

Examples


Functions.arithmeticMean({ 10, 20});        // 15.0
Functions.arithmeticMean({-20, 20});        //  0.0
Functions.arithmeticMean({ 10, 20},{1,10}); // 19.09..
Functions.arithmeticMean({ 10, 20},{1,-1}); // 10.

See also

ArithmeticMean, geometricMean

Inputs

TypeNameDefaultDescription
RealxVector input
Realweightsones(size(x, 1))Vector of weights

Outputs

TypeNameDefaultDescription
Realy