Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. ARRAY Standard Deviation vb.net

ARRAY Standard Deviation vb.net

Scheduled Pinned Locked Moved Visual Basic
csharpdata-structureshelpquestion
13 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PAguilar09
    wrote on last edited by
    #1

    I am trying to get the standard deviation of values that a user enters into a textbox and then will hit a display button, the following is what i have coded so far but For some reason i am getting the wrong answers for stdeviation and the sum of deviations PLEASE HELP Dim iSum as integer = 0 Dim dFAvg as double = 0 Dim dDev as double = 0 dim dSqDev as double = 0 For count = 0 To strArr.Length - 1 'add user entered values to list box lstGrades.Items.Add(strArr(count)) lblGrades.Text = lstGrades.Items.Count iSum += Convert.ToDouble(strArr(count)) 'get sum of values entered and pass to storing variable lblSum.Text = iSum 'display sum in label box '*********************** dFAvg = iSum / Convert.ToDouble(lblGrades.Text) 'calculate average '*********************** 'THIS IS WHAT IS NOT CALCULATING CORRECTLY!!!!!! dDev = ((strArr(count) - dFAvg) ^ 2) 'for each value the user enters it is supposed to be subtracted by the MEAN(dFAvg) and then raised by 2 'then i store each answer into dDev VARIABLE and then find the sum of all the values in dDev and assign it to dSqDev 'but i dont understand what i am doing wrong PLEASE HELP dSqDev += dDev Next 'end for lblSumDev.Text = FormatNumber(dSqDev, 2)

    H L C P J 5 Replies Last reply
    0
    • P PAguilar09

      I am trying to get the standard deviation of values that a user enters into a textbox and then will hit a display button, the following is what i have coded so far but For some reason i am getting the wrong answers for stdeviation and the sum of deviations PLEASE HELP Dim iSum as integer = 0 Dim dFAvg as double = 0 Dim dDev as double = 0 dim dSqDev as double = 0 For count = 0 To strArr.Length - 1 'add user entered values to list box lstGrades.Items.Add(strArr(count)) lblGrades.Text = lstGrades.Items.Count iSum += Convert.ToDouble(strArr(count)) 'get sum of values entered and pass to storing variable lblSum.Text = iSum 'display sum in label box '*********************** dFAvg = iSum / Convert.ToDouble(lblGrades.Text) 'calculate average '*********************** 'THIS IS WHAT IS NOT CALCULATING CORRECTLY!!!!!! dDev = ((strArr(count) - dFAvg) ^ 2) 'for each value the user enters it is supposed to be subtracted by the MEAN(dFAvg) and then raised by 2 'then i store each answer into dDev VARIABLE and then find the sum of all the values in dDev and assign it to dSqDev 'but i dont understand what i am doing wrong PLEASE HELP dSqDev += dDev Next 'end for lblSumDev.Text = FormatNumber(dSqDev, 2)

      H Offline
      H Offline
      Henry Minute
      wrote on last edited by
      #2

      This at least the third time I have seen you asking the same question. In all of them your code is unformatted and uncoloured. It is therefore very difficult to read, which cuts down on the number of people willing to try to plough through it in order to attempt to help you. Edit your post (above), put a <pre> tag on the line above your code and a </pre> tag on the line after your code. Then put back the indentation so that people at least have a chance to read and understand it. Have you tried Googling for this? I googled on vb.net calculate standard deviation and I got loads of hits with fully working code examples. Why not try that yourself?

      Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

      P 1 Reply Last reply
      0
      • P PAguilar09

        I am trying to get the standard deviation of values that a user enters into a textbox and then will hit a display button, the following is what i have coded so far but For some reason i am getting the wrong answers for stdeviation and the sum of deviations PLEASE HELP Dim iSum as integer = 0 Dim dFAvg as double = 0 Dim dDev as double = 0 dim dSqDev as double = 0 For count = 0 To strArr.Length - 1 'add user entered values to list box lstGrades.Items.Add(strArr(count)) lblGrades.Text = lstGrades.Items.Count iSum += Convert.ToDouble(strArr(count)) 'get sum of values entered and pass to storing variable lblSum.Text = iSum 'display sum in label box '*********************** dFAvg = iSum / Convert.ToDouble(lblGrades.Text) 'calculate average '*********************** 'THIS IS WHAT IS NOT CALCULATING CORRECTLY!!!!!! dDev = ((strArr(count) - dFAvg) ^ 2) 'for each value the user enters it is supposed to be subtracted by the MEAN(dFAvg) and then raised by 2 'then i store each answer into dDev VARIABLE and then find the sum of all the values in dDev and assign it to dSqDev 'but i dont understand what i am doing wrong PLEASE HELP dSqDev += dDev Next 'end for lblSumDev.Text = FormatNumber(dSqDev, 2)

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        Henry is right, your code needs proper formatting. Use PRE tags and you will probably be able to see what is wrong yourself. Hint: your calculations are completely wrong. :)

        Luc Pattyn


        I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


        H 1 Reply Last reply
        0
        • L Luc Pattyn

          Henry is right, your code needs proper formatting. Use PRE tags and you will probably be able to see what is wrong yourself. Hint: your calculations are completely wrong. :)

          Luc Pattyn


          I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


          H Offline
          H Offline
          Henry Minute
          wrote on last edited by
          #4

          Luc, Thank you for your support. I shall wear it always! :laugh:

          Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

          L 1 Reply Last reply
          0
          • H Henry Minute

            Luc, Thank you for your support. I shall wear it always! :laugh:

            Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            You're welcome. And don't you worry, there is a great deal of wear in it. :)

            Luc Pattyn


            I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages


            1 Reply Last reply
            0
            • P PAguilar09

              I am trying to get the standard deviation of values that a user enters into a textbox and then will hit a display button, the following is what i have coded so far but For some reason i am getting the wrong answers for stdeviation and the sum of deviations PLEASE HELP Dim iSum as integer = 0 Dim dFAvg as double = 0 Dim dDev as double = 0 dim dSqDev as double = 0 For count = 0 To strArr.Length - 1 'add user entered values to list box lstGrades.Items.Add(strArr(count)) lblGrades.Text = lstGrades.Items.Count iSum += Convert.ToDouble(strArr(count)) 'get sum of values entered and pass to storing variable lblSum.Text = iSum 'display sum in label box '*********************** dFAvg = iSum / Convert.ToDouble(lblGrades.Text) 'calculate average '*********************** 'THIS IS WHAT IS NOT CALCULATING CORRECTLY!!!!!! dDev = ((strArr(count) - dFAvg) ^ 2) 'for each value the user enters it is supposed to be subtracted by the MEAN(dFAvg) and then raised by 2 'then i store each answer into dDev VARIABLE and then find the sum of all the values in dDev and assign it to dSqDev 'but i dont understand what i am doing wrong PLEASE HELP dSqDev += dDev Next 'end for lblSumDev.Text = FormatNumber(dSqDev, 2)

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              You keep posting the same crappy code. I ask again, how is dividing the cumulative sum against the number of items what you want ? If you won't fix the most basic of poor decisions based on advice I've given you, then it seems like what you really want is for someone to do your homework for you. I suggest instead that you contact your teacher and tell them you are too dumb for their course. OR you could try to actually learn programming. Break the task down into steps. Work it out on paper so your steps lead to the right answer. Step through in the debugger and work out at what point your code is not doing what you expect it to.

              Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

              P P 2 Replies Last reply
              0
              • C Christian Graus

                You keep posting the same crappy code. I ask again, how is dividing the cumulative sum against the number of items what you want ? If you won't fix the most basic of poor decisions based on advice I've given you, then it seems like what you really want is for someone to do your homework for you. I suggest instead that you contact your teacher and tell them you are too dumb for their course. OR you could try to actually learn programming. Break the task down into steps. Work it out on paper so your steps lead to the right answer. Step through in the debugger and work out at what point your code is not doing what you expect it to.

                Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

                P Offline
                P Offline
                Paul Conrad
                wrote on last edited by
                #7

                Christian Graus wrote:

                Break the task down into steps. Work it out on paper so your steps lead to the right answer. Step through in the debugger and work out at what point your code is not doing what you expect it to.

                Excellent point.

                Christian Graus wrote:

                suggest instead that you contact your teacher and tell them you are too dumb for their course.

                Another excellent point :laugh:

                "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

                1 Reply Last reply
                0
                • P PAguilar09

                  I am trying to get the standard deviation of values that a user enters into a textbox and then will hit a display button, the following is what i have coded so far but For some reason i am getting the wrong answers for stdeviation and the sum of deviations PLEASE HELP Dim iSum as integer = 0 Dim dFAvg as double = 0 Dim dDev as double = 0 dim dSqDev as double = 0 For count = 0 To strArr.Length - 1 'add user entered values to list box lstGrades.Items.Add(strArr(count)) lblGrades.Text = lstGrades.Items.Count iSum += Convert.ToDouble(strArr(count)) 'get sum of values entered and pass to storing variable lblSum.Text = iSum 'display sum in label box '*********************** dFAvg = iSum / Convert.ToDouble(lblGrades.Text) 'calculate average '*********************** 'THIS IS WHAT IS NOT CALCULATING CORRECTLY!!!!!! dDev = ((strArr(count) - dFAvg) ^ 2) 'for each value the user enters it is supposed to be subtracted by the MEAN(dFAvg) and then raised by 2 'then i store each answer into dDev VARIABLE and then find the sum of all the values in dDev and assign it to dSqDev 'but i dont understand what i am doing wrong PLEASE HELP dSqDev += dDev Next 'end for lblSumDev.Text = FormatNumber(dSqDev, 2)

                  P Offline
                  P Offline
                  Paul Conrad
                  wrote on last edited by
                  #8

                  Reformat your code so it is easier to read (use

                  code block

                  tag) that aside, relook through the steps you are taking to solve the problem. You do have calculation mistakes and leaving it as an exercise for you to find.

                  "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

                  P 1 Reply Last reply
                  0
                  • P PAguilar09

                    I am trying to get the standard deviation of values that a user enters into a textbox and then will hit a display button, the following is what i have coded so far but For some reason i am getting the wrong answers for stdeviation and the sum of deviations PLEASE HELP Dim iSum as integer = 0 Dim dFAvg as double = 0 Dim dDev as double = 0 dim dSqDev as double = 0 For count = 0 To strArr.Length - 1 'add user entered values to list box lstGrades.Items.Add(strArr(count)) lblGrades.Text = lstGrades.Items.Count iSum += Convert.ToDouble(strArr(count)) 'get sum of values entered and pass to storing variable lblSum.Text = iSum 'display sum in label box '*********************** dFAvg = iSum / Convert.ToDouble(lblGrades.Text) 'calculate average '*********************** 'THIS IS WHAT IS NOT CALCULATING CORRECTLY!!!!!! dDev = ((strArr(count) - dFAvg) ^ 2) 'for each value the user enters it is supposed to be subtracted by the MEAN(dFAvg) and then raised by 2 'then i store each answer into dDev VARIABLE and then find the sum of all the values in dDev and assign it to dSqDev 'but i dont understand what i am doing wrong PLEASE HELP dSqDev += dDev Next 'end for lblSumDev.Text = FormatNumber(dSqDev, 2)

                    J Offline
                    J Offline
                    John M Bundy
                    wrote on last edited by
                    #9

                    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

                    1 Reply Last reply
                    0
                    • P Paul Conrad

                      Reformat your code so it is easier to read (use

                      code block

                      tag) that aside, relook through the steps you are taking to solve the problem. You do have calculation mistakes and leaving it as an exercise for you to find.

                      "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

                      P Offline
                      P Offline
                      PAguilar09
                      wrote on last edited by
                      #10

                      thanks i will do that next time i place code on the forums. i got it to work anyways but thanks!

                      1 Reply Last reply
                      0
                      • C Christian Graus

                        You keep posting the same crappy code. I ask again, how is dividing the cumulative sum against the number of items what you want ? If you won't fix the most basic of poor decisions based on advice I've given you, then it seems like what you really want is for someone to do your homework for you. I suggest instead that you contact your teacher and tell them you are too dumb for their course. OR you could try to actually learn programming. Break the task down into steps. Work it out on paper so your steps lead to the right answer. Step through in the debugger and work out at what point your code is not doing what you expect it to.

                        Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

                        P Offline
                        P Offline
                        PAguilar09
                        wrote on last edited by
                        #11

                        i got it to work on my own, didnt need ur help but thanks and God bless hope that you dnt treat all users the way you disrespected me.

                        1 Reply Last reply
                        0
                        • H Henry Minute

                          This at least the third time I have seen you asking the same question. In all of them your code is unformatted and uncoloured. It is therefore very difficult to read, which cuts down on the number of people willing to try to plough through it in order to attempt to help you. Edit your post (above), put a <pre> tag on the line above your code and a </pre> tag on the line after your code. Then put back the indentation so that people at least have a chance to read and understand it. Have you tried Googling for this? I googled on vb.net calculate standard deviation and I got loads of hits with fully working code examples. Why not try that yourself?

                          Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

                          P Offline
                          P Offline
                          PAguilar09
                          wrote on last edited by
                          #12

                          thanks i got it working on my own, i saw what was wrong and i will remember to post code correctly next time. thanks for your help and time

                          H 1 Reply Last reply
                          0
                          • P PAguilar09

                            thanks i got it working on my own, i saw what was wrong and i will remember to post code correctly next time. thanks for your help and time

                            H Offline
                            H Offline
                            Henry Minute
                            wrote on last edited by
                            #13

                            Good stuff!:thumbsup:

                            Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”

                            1 Reply Last reply
                            0
                            Reply
                            • Reply as topic
                            Log in to reply
                            • Oldest to Newest
                            • Newest to Oldest
                            • Most Votes


                            • Login

                            • Don't have an account? Register

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • World
                            • Users
                            • Groups