Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ncar!tank!paideia!vevea From: vevea@paideia.uchicago.edu (Jack L. Vevea) Newsgroups: comp.lang.c Subject: Re: Standard Deviation Message-ID: <2437@tank.uchicago.edu> Date: 24 Mar 89 05:36:32 GMT References: <2221@maccs.McMaster.CA> Sender: news@tank.uchicago.edu Reply-To: vevea@paideia.uchicago.edu (Jack L. Vevea) Organization: University of Chicago, Dept of Education Lines: 52 In article <2221@maccs.McMaster.CA> cs3b3aj@maccs.UUCP (Stephen M. Dunn) writes: > > 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); And this is precisely what Doug Gwynn was warning against in his earlier posting; if your numbers have variations of small magnitude, you will end up with more rounding error than meaning. Don't use this. >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); > And if the array already contains the squares, why square them again, pray? Try this: for(i=0;i