31 lines
658 B
Plaintext
31 lines
658 B
Plaintext
' FB 1.05.0 Win64
|
|
|
|
Function calcStandardDeviation(number As Double) As Double
|
|
Static a() As Double
|
|
Redim Preserve a(0 To UBound(a) + 1)
|
|
Dim ub As UInteger = UBound(a)
|
|
a(ub) = number
|
|
Dim sum As Double = 0.0
|
|
For i As UInteger = 0 To ub
|
|
sum += a(i)
|
|
Next
|
|
Dim mean As Double = sum / (ub + 1)
|
|
Dim diff As Double
|
|
sum = 0.0
|
|
For i As UInteger = 0 To ub
|
|
diff = a(i) - mean
|
|
sum += diff * diff
|
|
Next
|
|
Return Sqr(sum/ (ub + 1))
|
|
End Function
|
|
|
|
Dim a(0 To 7) As Double = {2, 4, 4, 4, 5, 5, 7, 9}
|
|
|
|
For i As UInteger = 0 To 7
|
|
Print "Added"; a(i); " SD now : "; calcStandardDeviation(a(i))
|
|
Next
|
|
|
|
Print
|
|
Print "Press any key to quit"
|
|
Sleep
|