Click here to Skip to main content
15,915,019 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: ARRAY Standard Deviation vb.net Pin
Henry Minute28-Oct-09 10:44
Henry Minute28-Oct-09 10:44 
GeneralRe: ARRAY Standard Deviation vb.net Pin
Luc Pattyn28-Oct-09 10:49
sitebuilderLuc Pattyn28-Oct-09 10:49 
AnswerRe: ARRAY Standard Deviation vb.net Pin
Christian Graus28-Oct-09 11:11
protectorChristian Graus28-Oct-09 11:11 
GeneralRe: ARRAY Standard Deviation vb.net Pin
Paul Conrad28-Oct-09 11:54
professionalPaul Conrad28-Oct-09 11:54 
GeneralRe: ARRAY Standard Deviation vb.net Pin
PAguilar0929-Oct-09 8:51
PAguilar0929-Oct-09 8:51 
AnswerRe: ARRAY Standard Deviation vb.net Pin
Paul Conrad28-Oct-09 11:56
professionalPaul Conrad28-Oct-09 11:56 
GeneralRe: ARRAY Standard Deviation vb.net Pin
PAguilar0929-Oct-09 8:47
PAguilar0929-Oct-09 8:47 
AnswerRe: ARRAY Standard Deviation vb.net Pin
John M Bundy29-Oct-09 8:40
John M Bundy29-Oct-09 8:40 
You are getting the incorrect result because you are trying to get the mean as a running total, and dividing only part of true mean, here is what i mean:

dFAvg = iSum / Convert.ToDouble(lblGrades.Text) 'calculate average


but the way you are calling it in the loop the first time you calculate the mean you are using only one number, then performing your deviation with that. The next loop you have the mean of 2 numbers and use that for your calculations. So what you want to do is load everything and calculate the mean, then use that to loop through and plug into your calculations. The below works:

  Dim iSum As Integer = 0
        Dim dFAvg As Double = 0
        Dim dDev As Double = 0
        Dim dSqDev As Double = 0
        Dim strArr As Array = {1, 3, 4, 6, 9, 19}

        For count = 0 To strArr.Length - 1
            iSum += Convert.ToDouble(strArr(count))             
lstGrades.Items.Add(strArr(count))
            lblGrades.Text = lstGrades.Items.Count
            lblSum.Text = iSum 'display sum in label box
            dFAvg = iSum / Convert.ToDouble(lblGrades.Text) 'calculate average
        Next
        For count = 0 To strArr.Length - 1
            dDev = ((strArr(count) - dFAvg) ^ 2)
            dSqDev += dDev
        Next 'end for
        lblSumDev.Text = FormatNumber(dSqDev, 2)
    End Sub

QuestionWindows Mobile Pin
PRT928-Oct-09 7:28
PRT928-Oct-09 7:28 
AnswerRe: Windows Mobile Pin
EliottA28-Oct-09 8:44
EliottA28-Oct-09 8:44 
QuestionFilling an Upload Form within a WebBrowser Pin
Nowid5028-Oct-09 6:58
Nowid5028-Oct-09 6:58 
Questionvb6 to vb.net help needed Pin
offroaderdan28-Oct-09 2:51
offroaderdan28-Oct-09 2:51 
AnswerRe: vb6 to vb.net help needed Pin
DaveAuld28-Oct-09 3:00
professionalDaveAuld28-Oct-09 3:00 
GeneralRe: vb6 to vb.net help needed Pin
offroaderdan28-Oct-09 3:56
offroaderdan28-Oct-09 3:56 
GeneralRe: vb6 to vb.net help needed Pin
offroaderdan28-Oct-09 4:03
offroaderdan28-Oct-09 4:03 
AnswerRe: vb6 to vb.net help needed Pin
EliottA28-Oct-09 4:20
EliottA28-Oct-09 4:20 
GeneralRe: vb6 to vb.net help needed Pin
offroaderdan28-Oct-09 4:24
offroaderdan28-Oct-09 4:24 
GeneralRe: vb6 to vb.net help needed Pin
Dave Kreskowiak28-Oct-09 4:55
mveDave Kreskowiak28-Oct-09 4:55 
GeneralRe: vb6 to vb.net help needed Pin
offroaderdan28-Oct-09 5:09
offroaderdan28-Oct-09 5:09 
GeneralRe: vb6 to vb.net help needed Pin
offroaderdan28-Oct-09 5:17
offroaderdan28-Oct-09 5:17 
GeneralRe: vb6 to vb.net help needed Pin
EliottA28-Oct-09 5:56
EliottA28-Oct-09 5:56 
GeneralRe: vb6 to vb.net help needed [modified] Pin
DaveAuld28-Oct-09 6:53
professionalDaveAuld28-Oct-09 6:53 
GeneralRe: vb6 to vb.net help needed Pin
offroaderdan28-Oct-09 7:40
offroaderdan28-Oct-09 7:40 
GeneralRe: vb6 to vb.net help needed Pin
DaveAuld28-Oct-09 8:11
professionalDaveAuld28-Oct-09 8:11 
GeneralRe: vb6 to vb.net help needed Pin
offroaderdan28-Oct-09 23:53
offroaderdan28-Oct-09 23:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.