Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

STDEV Help

Status
Not open for further replies.

JackSkellington

Technical User
Jul 28, 2005
86
GB
I have the current code calculating STDEV but there seems to be a problem because the anwer returned is incorrect, any idea's why?

Code:
Sub Main()
        Dim idx As Integer = 0
        Dim Sumsq As Double = 0
        Dim Score As Double = 0
        Dim sq As Double = 0
        Dim theCount As Integer = 4
        Dim arrValue As Int32() = {(5), (6), (8), (9)}
        Dim theMean As Integer = 7
        Dim sqr As Double = 0

        If Not arrValue Is Nothing Then
            If theCount > 0 Then
                For idx = 0 To theCount - 1
                    Score = arrValue(idx) - theMean
                    sq = Math.Pow(Score, 2)
                    Sumsq = Sumsq + sq

                Next

            End If
            Sumsq = Sumsq / (theCount - 1)
            sqr = Math.Abs(Math.Sqrt(Sumsq))
            ' should get 1.5811388300841898
        End If
 
This code is correct problem was i was comparing the answer to an STDEVP function in SQL thanks anyway
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top