NAG Library Routine Document

s14ccf (beta_incomplete)


    1  Purpose
    7  Accuracy


s14ccf computes values for the incomplete beta function Ixa,b and its complement 1-Ixa,b.


Fortran Interface
Subroutine s14ccf ( a, b, x, w, w1, ifail)
Integer, Intent (Inout):: ifail
Real (Kind=nag_wp), Intent (In):: a, b, x
Real (Kind=nag_wp), Intent (Out):: w, w1
C Header Interface
#include nagmk26.h
void  s14ccf_ (const double *a, const double *b, const double *x, double *w, double *w1, Integer *ifail)


s14ccf evaluates the incomplete beta function and its complement in the normalized form
Ixa,b = 1 Ba,b 0 x ta-1 1-t b-1 dt 1Ix a,b = Iy b,a , where ​ y=1-x ,  
Several methods are used to evaluate the functions depending on the arguments a, b and x. The methods include Wise's asymptotic expansion (see Wise (1950)) when a>b, continued fraction derived by DiDonato and Morris (1992) when a, b>1, and power series when b1 or b×x0.7. When both a and b are large, specifically a, b15, the DiDonato and Morris (1992) asymptotic expansion is employed for greater efficiency.
Once either Ixa,b or Iyb,a is computed, the other is obtained by subtraction from 1. In order to avoid loss of relative precision in this subtraction, the smaller of Ixa,b and Iyb,a is computed first.
s14ccf is derived from BRATIO in DiDonato and Morris (1992).


DiDonato A R and Morris A H (1992) Algorithm 708: Significant digit computation of the incomplete beta function ratios ACM Trans. Math. Software 18 360–373
Wise M E (1950) The incomplete beta function as a contour integral and a quickly converging series for its inverse Biometrika 37 208–218


1:     a – Real (Kind=nag_wp)Input
On entry: the argument a of the function.
Constraint: a0.0.
2:     b – Real (Kind=nag_wp)Input
On entry: the argument b of the function.
  • b0.0;
  • either b0.0 or a0.0.
3:     x – Real (Kind=nag_wp)Input
On entry: x, upper limit of integration.
  • 0.0x1.0;
  • either x0.0 or a0.0;
  • either 1-x0.0 or b0.0.
4:     w – Real (Kind=nag_wp)Output
On exit: the value of the incomplete beta function Ixa,b evaluated from zero to x.
5:     w1 – Real (Kind=nag_wp)Output
On exit: the value of the complement of the incomplete beta function 1-Ixa,b, i.e., the incomplete beta function evaluated from x to one.
6:     ifail – IntegerInput/Output
On entry: ifail must be set to 0, -1​ or ​1. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value -1​ or ​1 is recommended. If the output of error messages is undesirable, then the value 1 is recommended. Otherwise, if you are not familiar with this argument, the recommended value is 0. When the value -1​ or ​1 is used it is essential to test the value of ifail on exit.
On exit: ifail=0 unless the routine detects an error or a warning has been flagged (see Section 6).

Error Indicators and Warnings

If on entry ifail=0 or -1, explanatory error messages are output on the current error message unit (as defined by x04aaf).
Errors or warnings detected by the routine:
On entry, a=value.
Constraint: a0.0.
On entry, b=value.
Constraint: b0.0.
On entry, a and b were zero.
Constraint: a or b must be nonzero.
On entry, x=value.
Constraint: 0.0x1.0.
On entry, x and a were zero.
Constraint: x or a must be nonzero.
On entry, 1.0-x and b were zero.
Constraint: 1.0-x or b must be nonzero.
An unexpected error has been triggered by this routine. Please contact NAG.
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.


s14ccf is designed to maintain relative accuracy for all arguments. For very tiny results (of the order of machine precision or less) some relative accuracy may be lost – loss of three or four decimal places has been observed in experiments. For other arguments full relative accuracy may be expected.

Parallelism and Performance

s14ccf is not threaded in any implementation.

Further Comments



This example reads values of the arguments a and b from a file, evaluates the function and its complement for 10 different values of x and prints the results.

Program Text

Program Text (s14ccfe.f90)

Program Data

Program Data (s14ccfe.d)

Program Results

Program Results (s14ccfe.r)

© The Numerical Algorithms Group Ltd, Oxford, UK. 2017