GRASS Programmer's Manual  6.4.2(2012)
weisberg.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <math.h>
00004 #include "local_proto.h"
00005 
00006 
00007 double *weisberg_bingham(double *x, int n)
00008 {
00009     static double y[2];
00010     double suma = 0.0, sumb = 0.0, sumc = 0.0, sumd = 0.0, z, *xcopy;
00011     int i;
00012 
00013     if ((xcopy = (double *)malloc(n * sizeof(double))) == NULL) {
00014         fprintf(stderr, "Memory error in shapiro_francia\n");
00015         exit(EXIT_FAILURE);
00016     }
00017 
00018     for (i = 0; i < n; ++i)
00019         xcopy[i] = x[i];
00020 
00021     qsort(xcopy, n, sizeof(double), dcmp);
00022 
00023     for (i = 0; i < n; ++i) {
00024         z = xinormal((i + 1 - 0.375) / (n + 0.25));
00025         suma += z * xcopy[i];
00026         sumb += z * z;
00027         sumc += xcopy[i];
00028         sumd += xcopy[i] * xcopy[i];
00029     }
00030 
00031     y[0] = suma * suma / sumb / (sumd - sumc * sumc / n);
00032 
00033 #ifdef NOISY
00034     fprintf(stdout, "  TEST14 SF(N)  =%10.4f\n", y[0]);
00035 #endif /* NOISY */
00036 
00037     free(xcopy);
00038 
00039     return y;
00040 }                               /* test14_ */
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines