GRASS GIS 7 Programmer's Manual  7.7.svn(2018)-r73390
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
weisberg.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_weisberg_bingham(double *x, int n)
8 {
9  static double y[2];
10  double suma = 0.0, sumb = 0.0, sumc = 0.0, sumd = 0.0, z, *xcopy;
11  int i;
12 
13  if ((xcopy = (double *)malloc(n * sizeof(double))) == NULL) {
14  fprintf(stderr, "Memory error in Cdhc_shapiro_francia\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), Cdhc_dcmp);
22 
23  for (i = 0; i < n; ++i) {
24  z = Cdhc_xinormal((i + 1 - 0.375) / (n + 0.25));
25  suma += z * xcopy[i];
26  sumb += z * z;
27  sumc += xcopy[i];
28  sumd += xcopy[i] * xcopy[i];
29  }
30 
31  y[0] = suma * suma / sumb / (sumd - sumc * sumc / n);
32 
33 #ifdef NOISY
34  fprintf(stdout, " TEST14 SF(N) =%10.4f\n", y[0]);
35 #endif /* NOISY */
36 
37  free(xcopy);
38 
39  return y;
40 } /* test14_ */
void free(void *)
#define NULL
Definition: ccmath.h:32
#define x
void * malloc(YYSIZE_T)
double * Cdhc_weisberg_bingham(double *x, int n)
Definition: weisberg.c:7
double Cdhc_xinormal(double pee)
Definition: xinormal.c:5
int Cdhc_dcmp(const void *i, const void *j)
Definition: dcmp.c:1