dagstndn.c 969 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include "local_proto.h"
  5. double *Cdhc_dagostino_d(double *x, int n)
  6. {
  7. int i;
  8. static double y[2];
  9. double d, s, t = 0., *xcopy, m2, s1 = 0., s2, mn = 0.0;
  10. if ((xcopy = (double *)malloc(n * sizeof(double))) == NULL) {
  11. fprintf(stderr, "Memory allocation error\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. t += xcopy[i] * ((i + 1) - 0.5 * (n + 1));
  19. mn += xcopy[i];
  20. }
  21. m2 = mn / n;
  22. for (i = 0; i < n; ++i)
  23. s1 += (xcopy[i] - m2) * (xcopy[i] - m2);
  24. s2 = s1 / n;
  25. s = sqrt(s2);
  26. d = t / (n * n * s);
  27. /* y[0] = (d - 1. / (2*sqrt (M_PI))) * sqrt ((double)n) / 0.02998598; */
  28. y[0] = d;
  29. y[1] = sqrt((double)n) * (y[0] - 0.28209479) / 0.02998598;
  30. #ifdef NOISY
  31. fprintf(stdout, " TEST4 DAGN =%10.4f\n", y[0]);
  32. #endif /* NOISY */
  33. return y;
  34. }