Calculate standard deviation

master
neingeist 11 years ago
parent 83f056effc
commit e646660868

@ -31,6 +31,10 @@ double sample_variance(double set[], int set_n) {
return ss; return ss;
} }
double sample_stddev(double set[], int set_n) {
return sqrt(sample_variance(set, set_n));
}
int main() { int main() {
// Some data // Some data
double d[] = {7, 8, 5, 1, 6, 2}; 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(d, d_n), 7.766, 0.001));
assert(isalmost(sample_variance(e, e_n), 41.564, 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 Range
// XXX Mode // XXX Mode
// XXX Percentile // XXX Percentile

Loading…
Cancel
Save