in reply to Re: Answer: How do I get the root mean square of a list?
in thread How do I get the root mean square of a list?
And, of course, if your set of numbers is a sample set from a random distribution, the standard deviation of the numbers is a biased predictor of the true standard deviation, so you may prefer the following:sub std_dev { my ($sum, $sqr_sum); for (@_) { $sum += $_; $sqr_sum += $_ * $_; } sqrt(($sqr_sum - $sum * $sum / @_)/@_); }
# Produces an unbiased estimate of a standard deviation # from a sample sub std_dev_samp { my ($sum, $sqr_sum); for (@_) { $sum += $_; $sqr_sum += $_ * $_; } sqrt(($sqr_sum - $sum * $sum / @_)/$#_); }
|
|---|