GRASS Programmer's Manual
6.4.2(2012)
Main Page
Related Pages
Namespaces
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Pages
dagstndn.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
*
dagostino_d
(
double
*x,
int
n)
8
{
9
int
i;
10
static
double
y[2];
11
double
d,
s
, t = 0., *xcopy, m2, s1 = 0., s2, mn = 0.0;
12
13
if
((xcopy = (
double
*)malloc(n *
sizeof
(
double
))) ==
NULL
) {
14
fprintf(stderr,
"Memory allocation error\n"
);
15
exit(EXIT_FAILURE);
16
}
17
18
for
(i = 0; i < n; ++i)
19
xcopy[i] = x[i];
20
21
qsort(xcopy, n,
sizeof
(
double
),
dcmp
);
22
23
for
(i = 0; i < n; ++i) {
24
t += xcopy[i] * ((i + 1) - 0.5 * (n + 1));
25
mn += xcopy[i];
26
}
27
28
m2 = mn / n;
29
for
(i = 0; i < n; ++i)
30
s1 += (xcopy[i] - m2) * (xcopy[i] - m2);
31
32
s2 = s1 / n;
33
s = sqrt(s2);
34
d = t / (n * n *
s
);
35
36
/* y[0] = (d - 1. / (2*sqrt (M_PI))) * sqrt ((double)n) / 0.02998598; */
37
y[0] = d;
38
y[1] = sqrt((
double
)n) * (y[0] - 0.28209479) / 0.02998598;
39
40
#ifdef NOISY
41
fprintf(stdout,
" TEST4 DAGN =%10.4f\n"
, y[0]);
42
#endif
/* NOISY */
43
44
return
y;
45
}
lib
cdhc
dagstndn.c
Generated on Wed Jun 6 2012 14:04:20 for GRASS Programmer's Manual by
1.8.1