[Overview][Constants][Types][Classes][Procedures and functions][Index] |
Return variance of values
Source position: math.pp line 525
function Variance( |
const data: array of Single |
):Float; |
const data: PSingle; |
const N: Integer |
):Float; |
const data: array of Double |
):Float; |
const data: PDouble; |
const N: Integer |
):Float; |
const data: array of Extended |
):Float; |
const data: PExtended; |
const N: Integer |
):Float; |
Variance returns the variance of the values in the data array. It returns zero if there is only one value.
The second form of the function accepts a pointer to an array of N values.
None.
|
Return total variance of values |
|
|
Return standard deviation of data |
|
|
Return mean value of array |
Program Example50; { Program to demonstrate the Variance function. } { @ should return typed pointer } {$T+} Uses math; Var I : 1..100; ExArray : Array[1..100] of Float; V : float; begin Randomize; for I:=low(ExArray) to high(ExArray) do ExArray[i]:=(Random-Random)*100; V:=Variance(ExArray); Writeln('Variance : ',V:8:4); V:=Variance(@ExArray[1],100); Writeln('Variance (b) : ',V:8:4); end.
Program Example51; { Program to demonstrate the Variance function. It demonstrates the absence of large errors in the calculation. } Uses math; const Size = 1000000; var dataS: array of Single; dataD: array of Double; dataE: array of Extended; i,n: longint; begin WriteLn('Each run should return a value near unity.'); WriteLn('Single:'); SetLength( dataS, Size ); for n := 1 to 4 do begin for i := 0 to Size - 1 do begin dataS[i] := 10000000 + RandG(0,1); end; WriteLn( Math.Variance( dataS ):5:3 ); end; WriteLn('Double:'); SetLength( dataD, Size ); for n := 1 to 4 do begin for i := 0 to Size - 1 do begin dataD[i] := 1000000000000000 + RandG(0,1); end; WriteLn( Math.Variance( dataD ):5:3 ); end; WriteLn('Extended:'); SetLength( dataE, Size ); for n := 1 to 4 do begin for i := 0 to Size - 1 do begin dataE[i] := 1000000000000000000 + RandG(0,1); end; WriteLn( Math.Variance( dataE ):5:3 ); end; end.