fun8_2_std.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //
  2. // File: std.cpp
  3. //
  4. // MATLAB Coder version : 5.2
  5. // C/C++ source code generated on : 10-Mar-2023 11:08:29
  6. //
  7. // Include Files
  8. #include "fun8_2_std.h"
  9. #include "rt_nonfinite.h"
  10. #include "coder_array.h"
  11. #include <cmath>
  12. // Function Definitions
  13. //
  14. // Arguments : const ::coder::array<double, 2U> &x
  15. // Return Type : double
  16. //
  17. namespace coder {
  18. double b_std_8_2(const ::coder::array<double, 2U> &x)
  19. {
  20. array<double, 1U> absdiff;
  21. double y;
  22. int n;
  23. n = x.size(1);
  24. if (x.size(1) == 0) {
  25. y = rtNaN;
  26. } else if (x.size(1) == 1) {
  27. if ((!std::isinf(x[0])) && (!std::isnan(x[0]))) {
  28. y = 0.0;
  29. } else {
  30. y = rtNaN;
  31. }
  32. } else {
  33. double bsum;
  34. double xbar;
  35. int firstBlockLength;
  36. int k;
  37. int lastBlockLength;
  38. int nblocks;
  39. if (x.size(1) <= 1024) {
  40. firstBlockLength = x.size(1);
  41. lastBlockLength = 0;
  42. nblocks = 1;
  43. } else {
  44. firstBlockLength = 1024;
  45. nblocks = x.size(1) / 1024;
  46. lastBlockLength = x.size(1) - (nblocks << 10);
  47. if (lastBlockLength > 0) {
  48. nblocks++;
  49. } else {
  50. lastBlockLength = 1024;
  51. }
  52. }
  53. xbar = x[0];
  54. for (k = 2; k <= firstBlockLength; k++) {
  55. xbar += x[k - 1];
  56. }
  57. for (int ib{2}; ib <= nblocks; ib++) {
  58. int hi;
  59. firstBlockLength = (ib - 1) << 10;
  60. bsum = x[firstBlockLength];
  61. if (ib == nblocks) {
  62. hi = lastBlockLength;
  63. } else {
  64. hi = 1024;
  65. }
  66. for (k = 2; k <= hi; k++) {
  67. bsum += x[(firstBlockLength + k) - 1];
  68. }
  69. xbar += bsum;
  70. }
  71. xbar /= static_cast<double>(x.size(1));
  72. absdiff.set_size(x.size(1));
  73. for (k = 0; k < n; k++) {
  74. absdiff[k] = std::abs(x[k] - xbar);
  75. }
  76. n = x.size(1);
  77. y = 0.0;
  78. xbar = 3.3121686421112381E-170;
  79. for (k = 0; k < n; k++) {
  80. if (absdiff[k] > xbar) {
  81. bsum = xbar / absdiff[k];
  82. y = y * bsum * bsum + 1.0;
  83. xbar = absdiff[k];
  84. } else {
  85. bsum = absdiff[k] / xbar;
  86. y += bsum * bsum;
  87. }
  88. }
  89. y = xbar * std::sqrt(y);
  90. y /= std::sqrt(static_cast<double>(x.size(1)) - 1.0);
  91. }
  92. return y;
  93. }
  94. } // namespace coder
  95. //
  96. // File trailer for std.cpp
  97. //
  98. // [EOF]
  99. //