11 double sqrt2, mean = 0.0, sdx = 0.0, *xcopy, fx;
13 if ((xcopy = (
double *)
malloc(n *
sizeof(
double))) ==
NULL) {
14 fprintf(stderr,
"Memory error in anderson_darling\n");
18 sqrt2 = sqrt((
double)2.0);
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 xcopy[i] = (xcopy[i] - mean) / sdx;
34 for (i = 0; i <
n; ++i) {
35 fx = 0.5 +
normp(xcopy[i] / sqrt2) / 2.0;
43 (2.0 * i + 1.0) *
log(fx) + (2.0 * (n - i) - 1.0) *
log(1 - fx);
46 y[0] = y[1] * (0.75 / n + 1.0 + 2.25 / (n *
n));
49 fprintf(stdout,
" TEST8 AD(N) =%10.4f\n", y[0]);
int dcmp(const void *i, const void *j)
double * anderson_darling(double *x, int n)