Standard deviation

This is a discussion on Standard deviation within the C++ Programming forums, part of the General Programming Boards category; Code: //Here is what I got so far #include <iostream> using namespace std; int main () { int n, median; ...

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    102

    Standard deviation

    Code:
    //Here is what I got so far
    #include <iostream>
    using namespace std;
    
    int main ()
    {
      int n, median;
      double standarddeviation;
      int num [31]={12, 13, 15, 16, 18, 19, 21, 34, 57, 32, 38, 213, 10, 14, 156, 172, 134, 143, 132, 139, 751, 30, 31, 81, 23, 41, 24, 51, 75, 91, 1234};
      int sum= 0;
      for (n=0; n<31; n++)
      sum = sum+num [n];
      double average=sum/31.0;
      standarddeviation=(num[n]-average)*(num[n]-average);//I want to multiply every number by itself, subtract from the mean and son on but I can't seem to get it
      cout<< sum<<endl;
      cout<<average<<endl;
      cout<<standarddeviation;
      return 0;
      
    }

  2. #2
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    839
    does this make your problem clearer?

    Code:
      for (n=0; n<31; n++)
      {
      sum = sum+num [n];
      } 
      double average=sum/31.0;
      standarddeviation=(num[n]-average)*(num[n]-average);//I want to multiply every number by itself, subtract from the mean and son on but I can't seem to get it

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,300
    Look at the standard deviation formula again. In no way does it involve an average as part of the calculation.
    You also need to calculate the sum of the squares of the input data as well as just the sum of the input data.
    Last of all, you will need the square root function.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,630
    Quote Originally Posted by iMalc
    Look at the standard deviation formula again. In no way does it involve an average as part of the calculation.
    But it does, specifically, the mean.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,300
    Quote Originally Posted by laserlight View Post
    But it does, specifically, the mean.
    Well it's squared, that's what I meant.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with standard deviation
    By belkins in forum C Programming
    Replies: 3
    Last Post: 10-28-2008, 11:04 PM
  2. Replies: 2
    Last Post: 08-13-2008, 08:02 AM
  3. Standard Deviation of an array of numbers...
    By Xenofizz in forum C++ Programming
    Replies: 4
    Last Post: 11-19-2003, 09:48 PM
  4. arrays and standard deviation
    By bruceness in forum C Programming
    Replies: 1
    Last Post: 10-28-2002, 08:35 PM
  5. Standard deviation, bubblesort and others
    By peter_pan in forum C++ Programming
    Replies: 1
    Last Post: 03-09-2002, 09:24 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21