The incomplete beta function Ix (a, b) for five different pairs of (a, b). Notice that the pairs (, ) and (, ) are related by reflection symmetry around the diagonal (cf. equation | 226 Chapter 6. Special Functions incomplete beta function Ix a b gure . The incomplete beta function Ix a b for five different pairs of a b . Notice that the pairs .5 and are related by reflection symmetry around the diagonal cf. equation . 0 Incomplete Beta Function Student s Distribution F-Distribution Cumulative Binomial Distribution The incomplete beta function is defined by Ix a b Bx a b ta-1 1 - t b-idt a b 0 B a b B a b J0 V V V It has the limiting values Io a b 0 Ii a b 1 and the symmetry relation Ix a b 1 - Ii-X b a Sample page from NUMERICAL RECIPES IN C THE ART OF SCIENTIFIC COMPUTING ISBN 0-521-43108-5 If a and b are both rather greater than one then Ix a b rises from near-zero to near-unity quite sharply at about x a a b . Figure plots the function for several pairs a b . Incomplete Beta Function 227 The incomplete beta function has a series expansion Ix a b xa 1 - x b aB a b 1 B a 1 n 1 xn i n 0B a b n 1 but this does not prove to be very useful in its numerical evaluation. Note however that the beta functions in the coefficients can be evaluated for each value of n with just the previous value and a few multiplies using equations and . The continued fraction representation proves to be much more useful where xa 1 - x b r 1 di d2 x a aB a b 1 1 1 a m a b m x 2m 1 - a 2m a 2m 1 m b m x 2m a 2m 1 a 2m This continued fraction converges rapidly for x a 1 a b 2 taking in the worst case O max a b iterations. But for x a 1 a b 2 we can just use the symmetry relation to obtain an equivalent computation where the continued fraction will also converge rapidly. Hence we have include float betai float a float b float x Returns the incomplete beta function Ix a b . float betacf float a float b float x float gammln float xx void nrerror char error_text float bt if x x nrerror Bad x in routine betai if x x bt else Factors in front of the continued .