gonum.org/v1/gonum@v0.14.0/mathext/betainc.go (about)

     1  // Copyright ©2016 The Gonum Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package mathext
     6  
     7  import "gonum.org/v1/gonum/mathext/internal/cephes"
     8  
     9  // RegIncBeta returns the value of the regularized incomplete beta function
    10  // I(x;a,b). It is defined as
    11  //
    12  //	I(x;a,b) = B(x;a,b) / B(a,b)
    13  //	         = Γ(a+b) / (Γ(a)*Γ(b)) * int_0^x u^(a-1) * (1-u)^(b-1) du.
    14  //
    15  // The domain of definition is 0 <= x <= 1, and the parameters a and b must be positive.
    16  // For other values of x, a, and b RegIncBeta will panic.
    17  func RegIncBeta(a, b float64, x float64) float64 {
    18  	return cephes.Incbet(a, b, x)
    19  }
    20  
    21  // InvRegIncBeta computes the inverse of the regularized incomplete beta function.
    22  // It returns the x for which
    23  //
    24  //	y = I(x;a,b)
    25  //
    26  // The domain of definition is 0 <= y <= 1, and the parameters a and b must be
    27  // positive. For other values of x, a, and b InvRegIncBeta will panic.
    28  func InvRegIncBeta(a, b float64, y float64) float64 {
    29  	if y < 0 || 1 < y {
    30  		panic("mathext: parameter out of range")
    31  	}
    32  	return cephes.Incbi(a, b, y)
    33  }