GRASS GIS 8 Programmer's Manual 8.3.2(2024)-exported
Loading...
Searching...
No Matches
watsonue.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
6double *Cdhc_watson_u2_exp(double *x, int n)
7{
8 double *xcopy, mean = 0.0, zbar = 0.0, fn2, fx, sum4 = 0.0;
9 static double y[2];
10 int i;
11
12 if ((xcopy = (double *)malloc(n * sizeof(double))) == NULL) {
13 fprintf(stderr, "Memory error in Cdhc_watson_u2_exp\n");
14 exit(EXIT_FAILURE);
15 }
16
17 for (i = 0; i < n; ++i) {
18 xcopy[i] = x[i];
19 mean += x[i];
20 }
21 mean /= n;
22
23 qsort(xcopy, n, sizeof(double), Cdhc_dcmp);
24
25 for (i = 0; i < n; ++i) {
26 fx = 1 - exp(-xcopy[i] / mean);
27 if (fx <= 1e-5)
28 fx = 1e-5;
29
30 if (fx >= 0.99999)
31 fx = 0.99999;
32
33 /* sum3 += 2 * (i + 1) * (log (fx) + log (1.0 - fx[n - i - 1])); */
34 fn2 = (2.0 * i + 1.0) / (2.0 * n);
35 sum4 += (fx - fn2) * (fx - fn2);
36 fn2 = (2.0 * (i + 1) - 1.0) / (2.0 * n);
37 zbar += fx;
38 }
39
40 zbar /= n;
41 y[0] = (1.0 / (n * 12) + sum4) - n * (zbar - .5) * (zbar - .5);
42 y[0] *= 1.0 + 0.16 / n;
43
44#ifdef NOISY
45 fprintf(stdout, " TEST19 WU2(E) =%10.4f\n", y[0]);
46#endif /* NOISY */
47
48 free(xcopy);
49
50 return y;
51}
#define NULL
Definition ccmath.h:32
int Cdhc_dcmp(const void *i, const void *j)
Definition dcmp.c:1
double * Cdhc_watson_u2_exp(double *x, int n)
Definition watsonue.c:6
#define x