Thread: Standard Deviation of an array of numbers...

1. Standard Deviation of an array of numbers...

I am writing a program that tells the user to enter 20 numbers, then it uses those and finds the average and standard deviation.

I put the 20 numbers in an array.

Does anyone know the c++ formula for standard deviation of an array? It's blowing my mind. I've been trying for hours.

2. I don't know what "standar deviation" is...someone else here might, but in the meantime it would help if you could explain it a bit.

Edit: after a google search I found one explanation:

standard deviation is the square root of the variance of a mean of a set of numbers

so for the set 1,2,3 the variance is:

( (1-avg)+(2-avg)+(3-avg) ) / n

in this case avg is 2 and n is 3

it also went on to say that you should divide by n-1 to give an unbiased estimate...although it didn't really explain why

If this is correct it shouldn't be too hard to do...

3. It's a real weird formula.

It's the square root of a summation of each number minus the average, squared and divided by the amount of numbers minus 1.

It's hard to explain, even harder to code.

4. Sounds like i had it somewhat correct, but I had an error, I meant to square those terms:

(1-avg)*(1-avg), etc

So you should be able to do something like:
Code:
```for (int i=0;i<n;i++)
total+=(nums[i]-avg)*(nums[i]-avg);
total/=n-1;
std::cout<<sqrt(total);```

5. Thanks!

I got it to work, I think. Even if not so, you helped a lot. Awesome!