weisberg.c 864 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include "local_proto.h"
  5. double *Cdhc_weisberg_bingham(double *x, int n)
  6. {
  7. static double y[2];
  8. double suma = 0.0, sumb = 0.0, sumc = 0.0, sumd = 0.0, z, *xcopy;
  9. int i;
  10. if ((xcopy = (double *)malloc(n * sizeof(double))) == NULL) {
  11. fprintf(stderr, "Memory error in Cdhc_shapiro_francia\n");
  12. exit(EXIT_FAILURE);
  13. }
  14. for (i = 0; i < n; ++i)
  15. xcopy[i] = x[i];
  16. qsort(xcopy, n, sizeof(double), Cdhc_dcmp);
  17. for (i = 0; i < n; ++i) {
  18. z = Cdhc_xinormal((i + 1 - 0.375) / (n + 0.25));
  19. suma += z * xcopy[i];
  20. sumb += z * z;
  21. sumc += xcopy[i];
  22. sumd += xcopy[i] * xcopy[i];
  23. }
  24. y[0] = suma * suma / sumb / (sumd - sumc * sumc / n);
  25. #ifdef NOISY
  26. fprintf(stdout, " TEST14 SF(N) =%10.4f\n", y[0]);
  27. #endif /* NOISY */
  28. free(xcopy);
  29. return y;
  30. } /* test14_ */