github.com/jingcheng-WU/gonum@v0.9.1-0.20210323123734-f1a2a11a8f7b/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 "github.com/jingcheng-WU/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  //  I(x;a,b) = B(x;a,b) / B(a,b)
    12  //           = Γ(a+b) / (Γ(a)*Γ(b)) * int_0^x u^(a-1) * (1-u)^(b-1) du.
    13  // The domain of definition is 0 <= x <= 1, and the parameters a and b must be positive.
    14  // For other values of x, a, and b RegIncBeta will panic.
    15  func RegIncBeta(a, b float64, x float64) float64 {
    16  	return cephes.Incbet(a, b, x)
    17  }
    18  
    19  // InvRegIncBeta computes the inverse of the regularized incomplete beta function.
    20  // It returns the x for which
    21  //  y = I(x;a,b)
    22  // The domain of definition is 0 <= y <= 1, and the parameters a and b must be
    23  // positive. For other values of x, a, and b InvRegIncBeta will panic.
    24  func InvRegIncBeta(a, b float64, y float64) float64 {
    25  	if y < 0 || 1 < y {
    26  		panic("mathext: parameter out of range")
    27  	}
    28  	return cephes.Incbi(a, b, y)
    29  }