GRASS GIS 7 Programmer's Manual
7.8.3(2020)-exported
andrsnde.c
Go to the documentation of this file.
1
#include <stdio.h>
2
#include <stdlib.h>
3
#include <math.h>
4
#include "local_proto.h"
5
6
7
double
*
Cdhc_anderson_darling_exp
(
double
*
x
,
int
n)
8
{
9
static
double
y[2];
10
double
sqrt2, mean = 0.0, *xcopy, fx, sum3 = 0.0;
11
int
i;
12
13
if
((xcopy = (
double
*)malloc(n *
sizeof
(
double
))) ==
NULL
) {
14
fprintf(stderr,
"Memory error in Cdhc_anderson_darling\n"
);
15
exit(EXIT_FAILURE);
16
}
17
18
sqrt2 = sqrt((
double
)2.0);
19
20
for
(i = 0; i < n; ++i) {
21
xcopy[i] =
x
[i];
22
mean +=
x
[i];
23
}
24
mean /= n;
25
qsort(xcopy, n,
sizeof
(
double
),
Cdhc_dcmp
);
26
27
for
(i = 0; i < n; ++i) {
28
fx = 1 - exp(-xcopy[i] / mean);
29
sum3 += (2.0 * i + 1) * (log(fx) - xcopy[n - i - 1] / mean);
30
}
31
32
y[0] = (1.0 + 0.3 / n) * (-n - sum3 / n);
33
#ifdef NOISY
34
fprintf(stdout,
" TEST20 AD(E) =%10.4f\n"
, y[0]);
35
#endif
/* NOISY */
36
37
free(xcopy);
38
39
return
y;
40
}
x
#define x
Cdhc_dcmp
int Cdhc_dcmp(const void *i, const void *j)
Definition:
dcmp.c:1
NULL
#define NULL
Definition:
ccmath.h:32
Cdhc_anderson_darling_exp
double * Cdhc_anderson_darling_exp(double *x, int n)
Definition:
andrsnde.c:7
cdhc
andrsnde.c
Generated on Tue May 5 2020 09:45:27 for GRASS GIS 7 Programmer's Manual by
1.8.17