GRASS Programmer's Manual  6.5.svn(2014)-r66266
 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 }
int dcmp(const void *i, const void *j)
Definition: dcmp.c:1
double * dagostino_d(double *x, int n)
Definition: dagstndn.c:7
int y
Definition: plot.c:34
void * malloc(YYSIZE_T)
return NULL
Definition: dbfopen.c:1394
int n
Definition: dataquad.c:291