Path: utzoo!yunexus!maccs!cs3b3aj From: cs3b3aj@maccs.McMaster.CA (Stephen M. Dunn) Newsgroups: comp.lang.c Subject: Re: Standard Deviation Message-ID: <2221@maccs.McMaster.CA> Date: 23 Mar 89 16:20:52 GMT Article-I.D.: maccs.2221 Reply-To: cs3b3aj@maccs.UUCP (Stephen M. Dunn) Organization: McMaster University, Hamilton, Ontario Lines: 36 Well, of course, the standard textbook methods of calculating the standard deviation are as follows: 1) assuming values are in array x, there are n values, and the mean is known and is in the variable mean: temp = 0; for (i = 1; i <= n; i++) temp += (x [i] - mean) ^ 2; std_dev = sqrt (temp / n); (note that my C is _so_ rusty, I'm not even sure if I did the exponentiation correctly! Anyway, the algorithm is right.) 2) assuming that the SQUARES of the values are in array x, there are n values, and the mean is known and is in the variable mean: temp = 0; for (i = 1; i <= n; i++) temp += x [i] ^ 2; std_dev = sqrt ((temp - (mean ^ 2) / n) / n); In both cases, temp, x and mean would likely be doubles, and n and i would be ints. Depending on the magnitudes of your numbers, one of these algorithms may be more accurate than the other. Hope these help. Regards, -- ====================================================================== ! Stephen M. Dunn, cs3b3aj@maccs.McMaster.CA ! DISCLAIMER: ! ! I always wanted to be a lumberjack! - M.P. ! I'm only an undergrad ! ======================================================================