What the hell is standard deviation anyway?
Well I wrote a prog to calculate the mean and standard devation of a set of numbers. The mean part was easy enough but I'm having probs with the standard deviation. Here is the code I'm using:
VB Code:
Dim X As Long Dim SumX1 As Single Dim SumX2 As Single Dim NumValues As Integer 'Seperate Numbers' Array1 = Split(txtNumbers.Text, ",") Total = 0 For X = 0 To UBound(Array1) Total = Total + Array1(X) Next X SumX1 = SumX1 + Total SumX2 = SumX2 + Total ^ 2 NumValues = UBound(Array1) + 1 'Calculate and Display Mean Mean = SumX1 / NumValues lblMean.Caption = Mean 'Calculate and Display Standard Deviation Stdev = Sqr((NumValues * SumX2 - SumX1 ^ 2) / (NumValues * (NumValues - 1))) lblDeviation.Caption = Stdev
I'm not getting the right answer for the standard deviation. So maybe one of you brainy guys could tell me where I've gone wrong.




Reply With Quote