From e6466608688d41e5ba8875dffa5412f11457ee8c Mon Sep 17 00:00:00 2001 From: neingeist Date: Fri, 14 Feb 2014 20:27:32 +0100 Subject: [PATCH] Calculate standard deviation --- av-variance.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/av-variance.c b/av-variance.c index f94ae8b..7a0b8f8 100644 --- a/av-variance.c +++ b/av-variance.c @@ -31,6 +31,10 @@ double sample_variance(double set[], int set_n) { return ss; } +double sample_stddev(double set[], int set_n) { + return sqrt(sample_variance(set, set_n)); +} + int main() { // Some data double d[] = {7, 8, 5, 1, 6, 2}; @@ -49,7 +53,9 @@ int main() { assert(isalmost(sample_variance(d, d_n), 7.766, 0.001)); assert(isalmost(sample_variance(e, e_n), 41.564, 0.001)); - // XXX Stddev + assert(isalmost(sample_stddev(d, d_n), 2.787, 0.001)); + assert(isalmost(sample_stddev(e, e_n), 6.447, 0.001)); + // XXX Range // XXX Mode // XXX Percentile