Dim lngMyNumb() As Long
Dim lngTot As Long
Dim i As Integer
ReDim lngMyNumb(3)
lngMyNumb(0) = 5
lngMyNumb(1) = 5
lngMyNumb(2) = 5
lngMyNumb(3) = 45
For i = 0 To UBound(lngMyNumb)
lngTot = lngTot + lngMyNumb(i)
Next
MsgBox "avg is " & lngTot / UBound(lngMyNumb)
Dim lngMyNumb() As Long
Dim lngTot As Long
Dim lngTotSq As Long
Dim i As Integer
ReDim lngMyNumb(3)
lngMyNumb(0) = 5
lngMyNumb(1) = 5
lngMyNumb(2) = 5
lngMyNumb(3) = 45
For i = 0 To UBound(lngMyNumb)
lngTot = lngTot + lngMyNumb(i)
lngTotSq = lngTotSq + (lngMyNumb(i)^2)
Next
MsgBox "avg is " & lngTot / UBound(lngMyNumb)
MsgBox "stddev is " & sqr((lngTotSq / UBound(lngMyNumb)) - ((lngTot / UBound(lngMyNumb))^2))
...I think...
[Edited by parksie on 11-27-2000 at 05:02 PM]
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You". -- Linus Torvalds
Thanks parksie, I would have included the standard deviation in my answer but I didn't know the formula. BTW I assume your reference to sqrt is just a typo and you meant Sqr.
Hey, guys: 0 to UBound is (UBound + 1 ) values. Perhaps (UBound + 1) should be the divsior.
Live long & prosper.
The Dinosaur from prehistoric era prior to computers.
Eschew obfuscation!
If a billion people believe a foolish idea, it is still a foolish idea!
VB.net 2010 Express
64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.
The computation for Standard Deveiation does not look right to me. Perhaps the following.
Code:
Dim FirstValue As Integer
Dim LastValue As Integer
Dim NumberValues As Integer
Dim J As Integer
Dim Total As Double
Dim Average As Double
Dim StandardDev As Double
FirstValue = LBound(MyArray,1)
LastValue = UBound(MyArray,1)
NumberValues = UBound - LBound + 1
Total = 0
For J = FirstValue to LastValue
Total = Total + MyArray(J)
Next J
Average = Total / NumberValues
Total = 0
For J = FirstValue to LastValue
Total = Total + (Average - MyArray(J))^2
Next J
StandardDev = sqr(Total / NumberValues)
Live long & prosper.
The Dinosaur from prehistoric era prior to computers.
Eschew obfuscation!
If a billion people believe a foolish idea, it is still a foolish idea!
VB.net 2010 Express
64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.
Both of the posted computations of the STD Dev are correct. The first is more efficient computationally, Use it. There could be some quibbeling about whether to divide by n or (n-1) but which ever the difference will be small.