11 double mean = 0.0, sdx = 0.0, fx, sqrt2, *xcopy;
13 sqrt2 = sqrt((
double)2.0);
16 if ((xcopy = (
double *)
malloc(n *
sizeof(
double))) ==
NULL) {
17 fprintf(stderr,
"Memory error in cramer_von_mises\n");
21 for (i = 0; i <
n; ++i) {
26 sdx = sqrt((n * sdx - mean * mean) / (n * (n - 1.0)));
29 qsort(xcopy, n,
sizeof(
double),
dcmp);
31 for (i = 0; i <
n; ++i) {
32 fx = 0.5 +
normp((xcopy[i] - mean) / sdx / sqrt2) / 2.0;
39 fx -= (2.0 * i + 1.0) / (2.0 *
n);
42 y[1] += 1.0 / (double)(n * 12);
43 y[0] = y[1] * (0.5 / n + 1.0);
46 fprintf(stdout,
" TEST9 CVM(N) =%10.4f\n", y[0]);
int dcmp(const void *i, const void *j)
double * cramer_von_mises(double *x, int n)