The SDL Component Suite is an industry leading collection of components supporting scientific and engineering computing. Please visit the SDL Web site for more information....


Class:TVector, TIntVector
Declaration:procedure MeanVar (LowElem, HighElem: integer; var Mean, Variance: double);

The method MeanVar calculates the mean and the variance of the vector elements within a specified range. The range of the vector elements which are used for the calculation is determined by the parameters LowElem and HighElem. If any of these parameters receives an invalid value, this value is automatically adjusted to nearest boundary value (either 1 or NrOfElem). Note, that in the case of the method MeanVar the vector is not considered as a vector in its usual sense but merely as a collection of numbers.

The variable parameters Mean and Variance return the mean and the variance of the selected data.

Hint 1: If there are less than three elements within the specified range of the vector the calculation of the variance is impossible. In this case a value of 1.0 is assigned to the variable Variance.

Hint 2: The function MeanVar assumes that the values used for the calculation of the variance are sample data. If you have to calculate the variance of a population (i.e. all values ever measured) you have to multiply the variance by a factor of  n/(n-1), with n being the number of values used for the calculation: n = (HighElem-LowElem+1).

Example: The statement Vec1.MeanVar (1,20,Mean,Vari); calculates the mean and the variance for the vector elements 1...20 and returns them in the variables Mean and Vari.

Example: This method is used in the following example program (see for downloading the code): testvec

Last Update: 2020-Aug-23