How do you perform standard deviation in c++, the addition of the difference between the mean and the current number gets to astronomical for what im using, no data type wrks HELP!!!!!!
Nate
This is a discussion on Standard Deviation in C++ within the C++ Programming forums, part of the General Programming Boards category; How do you perform standard deviation in c++, the addition of the difference between the mean and the current number ...
How do you perform standard deviation in c++, the addition of the difference between the mean and the current number gets to astronomical for what im using, no data type wrks HELP!!!!!!
Nate
How big are your numbers?
Doubles are plenty big on 32 bit compilers, I doubt you are exceeding their maximum.
Im taking the salaries of a baseball team which range from 200000 to 12000000, and have used doubles, long ints unsigned int, float unsigned float etc.
If you are using long doubles, they should be plenty in size unless you are really scrambling for sig figs.
Does this work?
There is another way to calculate std deviation by doingCode:#include <cmath> using namespace std; #include <cassert> double sum_squares(double data[], int n) { double sum = 0; for (int i = 0; i < n; ++i) sum += data[i] * data[i]; return sum; } double calc_std_deviation(double data[], int n) { assert(n > 1); double ss = sum_squares(data, n); return sqrt(ss / (n - 1)); }
some algebra on the summation and then getting a similar
formula.
Made a big mistake in that one as I forgot to
subtract x_i from the mean and then squaring that. On the division, when I divide by n-1 it is for the sample, dividing by n is for the population I think.