http://www.anthony-vba.kefra.com/index_002.htm
***********************************************************************
'* Mean *
'***********************************************************************
Function Mean(k As Long, Arr() As Single)
Dim Sum As Single
Dim i As Integer
Sum = 0
For i = 1 To k
Sum = Sum + Arr(i)
Next i
Mean = Sum / k
End Function
'************************************************************************
'* Standard Deviation *
'************************************************************************
Function StdDev(k As Long, Arr() As Single)
Dim i As Integer
Dim avg As Single, SumSq As Single
avg = Mean(k, Arr)
For i = 1 To k
SumSq = SumSq + (Arr(i) - avg) ^ 2
Next i
StdDev = Sqr(SumSq / (k - 1))
End Function
'*************************************************************************
'* Computation *
'*************************************************************************
Sub compute()
Dim Arr(10) As Single
Dim Average As Single
Dim Std_Dev As Single
For i = 1 To 10
Arr(i) = Sheets("Sheet1").Cells(i, 1)
Next i
Average = Mean(10, Arr)
Std_Dev = StdDev(10, Arr)
Sheets("Sheet1").Cells(12, 1) = Average
Sheets("Sheet1").Cells(13, 1) = Std_Dev
End Sub
No comments:
Post a Comment