double variance(long long *x, int n)
{
double m = x[0];
double s = 0;
int i;
for (i=0; idouble m_new = m + (x[i] - m)/(i+1);
s = s + (x[i] - m)*(x[i] - m_new);
m = m_new;
}
return s / (n - 1);
}
double mean(long long *x, int n)
{
double m = x[0];
int i;
for (i=0; im = m + (x[i] - m)/(i+1);
}
return m;
}
double stddev(long long *x, int n)
{
return sqrt(variance(x, n));
}
long long times[30];
printf("mean: %f stddev: %f\n", mean(times, 20), stddev(times, 20));
2008/07/23
A better average
登録:
コメントの投稿 (Atom)
0 件のコメント:
コメントを投稿