ObjectPascal
Mean
Function
Gives the average for a set of numbers Math unit
 function Mean ( const DataArray : array of Double ) : Extended;
Description
The Mean function returns the average of a set of Double values in a DataArray.
Related commands
Max Gives the maximum of two integer values
Min Gives the minimum of two integer values
CompareValue Compare numeric values with a tolerance
 
Example code : Calculate the mean of a set of 5 numbers
var
  numbers         : array[1..5] of Double;
  aveVal, meanVal : Double;

begin
  // Set up the array of 5 floating point numbers
  numbers[1] :=  1.0;
  numbers[2] :=  2.5;
  numbers[3] :=  3.0;
  numbers[4] :=  4.5;
  numbers[5] := 25.0;

  // Calculate the average of these numbers
  aveVal := (numbers[1] + numbers[2] + numbers[3] +
             numbers[4] + numbers[5]) / 5;

  // Calculate the mean of these numbers
  meanVal := Mean(numbers);

  // Show these values
  WriteLn('Average = '+FloatToStr(aveVal));
  WriteLn('Mean    = '+FloatToStr(meanVal));
end;
Show full unit code
   Average = 7.2
   Mean    = 7.2