GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-f63024f571
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 double *Cdhc_weisberg_bingham(double *x, int n)
7 {
8  static double y[2];
9  double suma = 0.0, sumb = 0.0, sumc = 0.0, sumd = 0.0, z, *xcopy;
10  int i;
11 
12  if ((xcopy = (double *)malloc(n * sizeof(double))) == NULL) {
13  fprintf(stderr, "Memory error in Cdhc_shapiro_francia\n");
14  exit(EXIT_FAILURE);
15  }
16 
17  for (i = 0; i < n; ++i)
18  xcopy[i] = x[i];
19 
20  qsort(xcopy, n, sizeof(double), Cdhc_dcmp);
21 
22  for (i = 0; i < n; ++i) {
23  z = Cdhc_xinormal((i + 1 - 0.375) / (n + 0.25));
24  suma += z * xcopy[i];
25  sumb += z * z;
26  sumc += xcopy[i];
27  sumd += xcopy[i] * xcopy[i];
28  }
29 
30  y[0] = suma * suma / sumb / (sumd - sumc * sumc / n);
31 
32 #ifdef NOISY
33  fprintf(stdout, " TEST14 SF(N) =%10.4f\n", y[0]);
34 #endif /* NOISY */
35 
36  free(xcopy);
37 
38  return y;
39 } /* test14_ */
#define NULL
Definition: ccmath.h:32
int Cdhc_dcmp(const void *i, const void *j)
Definition: dcmp.c:1
double Cdhc_xinormal(double)
Definition: xinormal.c:4
void * malloc(YYSIZE_T)
void free(void *)
double * Cdhc_weisberg_bingham(double *x, int n)
Definition: weisberg.c:6
#define x