gdtrf.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /* gdtrf.c
  2. *
  3. * Gamma distribution function
  4. *
  5. *
  6. *
  7. * SYNOPSIS:
  8. *
  9. * float a, b, x, y, gdtrf();
  10. *
  11. * y = gdtrf( a, b, x );
  12. *
  13. *
  14. *
  15. * DESCRIPTION:
  16. *
  17. * Returns the integral from zero to x of the gamma probability
  18. * density function:
  19. *
  20. *
  21. * x
  22. * b -
  23. * a | | b-1 -at
  24. * y = ----- | t e dt
  25. * - | |
  26. * | (b) -
  27. * 0
  28. *
  29. * The incomplete gamma integral is used, according to the
  30. * relation
  31. *
  32. * y = igam( b, ax ).
  33. *
  34. *
  35. * ACCURACY:
  36. *
  37. * Relative error:
  38. * arithmetic domain # trials peak rms
  39. * IEEE 0,100 5000 5.8e-5 3.0e-6
  40. *
  41. * ERROR MESSAGES:
  42. *
  43. * message condition value returned
  44. * gdtrf domain x < 0 0.0
  45. *
  46. */
  47. /* gdtrcf.c
  48. *
  49. * Complemented gamma distribution function
  50. *
  51. *
  52. *
  53. * SYNOPSIS:
  54. *
  55. * float a, b, x, y, gdtrcf();
  56. *
  57. * y = gdtrcf( a, b, x );
  58. *
  59. *
  60. *
  61. * DESCRIPTION:
  62. *
  63. * Returns the integral from x to infinity of the gamma
  64. * probability density function:
  65. *
  66. *
  67. * inf.
  68. * b -
  69. * a | | b-1 -at
  70. * y = ----- | t e dt
  71. * - | |
  72. * | (b) -
  73. * x
  74. *
  75. * The incomplete gamma integral is used, according to the
  76. * relation
  77. *
  78. * y = igamc( b, ax ).
  79. *
  80. *
  81. * ACCURACY:
  82. *
  83. * Relative error:
  84. * arithmetic domain # trials peak rms
  85. * IEEE 0,100 5000 9.1e-5 1.5e-5
  86. *
  87. * ERROR MESSAGES:
  88. *
  89. * message condition value returned
  90. * gdtrcf domain x < 0 0.0
  91. *
  92. */
  93. /* gdtr() */
  94. /*
  95. Cephes Math Library Release 2.2: July, 1992
  96. Copyright 1984, 1987, 1992 by Stephen L. Moshier
  97. Direct inquiries to 30 Frost Street, Cambridge, MA 02140
  98. */
  99. #include <math.h>
  100. #ifdef ANSIC
  101. float igamf(float, float), igamcf(float, float);
  102. #else
  103. float igamf(), igamcf();
  104. #endif
  105. float gdtrf( float aa, float bb, float xx )
  106. {
  107. float a, b, x;
  108. a = aa;
  109. b = bb;
  110. x = xx;
  111. if( x < 0.0 )
  112. {
  113. mtherr( "gdtrf", DOMAIN );
  114. return( 0.0 );
  115. }
  116. return( igamf( b, a * x ) );
  117. }
  118. float gdtrcf( float aa, float bb, float xx )
  119. {
  120. float a, b, x;
  121. a = aa;
  122. b = bb;
  123. x = xx;
  124. if( x < 0.0 )
  125. {
  126. mtherr( "gdtrcf", DOMAIN );
  127. return( 0.0 );
  128. }
  129. return( igamcf( b, a * x ) );
  130. }