gonum.org/v1/gonum@v0.14.0/mathext/gamma_inc.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 (
     8  	"gonum.org/v1/gonum/mathext/internal/cephes"
     9  )
    10  
    11  // GammaIncReg computes the regularized incomplete Gamma integral.
    12  //
    13  //	GammaIncReg(a,x) = (1/ Γ(a)) \int_0^x e^{-t} t^{a-1} dt
    14  //
    15  // The input argument a must be positive and x must be non-negative or GammaIncReg
    16  // will panic.
    17  //
    18  // See http://mathworld.wolfram.com/IncompleteGammaFunction.html
    19  // or https://en.wikipedia.org/wiki/Incomplete_gamma_function for more detailed
    20  // information.
    21  func GammaIncReg(a, x float64) float64 {
    22  	return cephes.Igam(a, x)
    23  }
    24  
    25  // GammaIncRegComp computes the complemented regularized incomplete Gamma integral.
    26  //
    27  //	GammaIncRegComp(a,x) = 1 - GammaIncReg(a,x)
    28  //	                     = (1/ Γ(a)) \int_x^\infty e^{-t} t^{a-1} dt
    29  //
    30  // The input argument a must be positive and x must be non-negative or
    31  // GammaIncRegComp will panic.
    32  func GammaIncRegComp(a, x float64) float64 {
    33  	return cephes.IgamC(a, x)
    34  }
    35  
    36  // GammaIncRegInv computes the inverse of the regularized incomplete Gamma integral. That is,
    37  // it returns the x such that:
    38  //
    39  //	GammaIncReg(a, x) = y
    40  //
    41  // The input argument a must be positive and y must be between 0 and 1
    42  // inclusive or GammaIncRegInv will panic. GammaIncRegInv should return a positive
    43  // number, but can return NaN if there is a failure to converge.
    44  func GammaIncRegInv(a, y float64) float64 {
    45  	return gammaIncRegInv(a, y)
    46  }
    47  
    48  // GammaIncRegCompInv computes the inverse of the complemented regularized incomplete Gamma
    49  // integral. That is, it returns the x such that:
    50  //
    51  //	GammaIncRegComp(a, x) = y
    52  //
    53  // The input argument a must be positive and y must be between 0 and 1
    54  // inclusive or GammaIncRegCompInv will panic. GammaIncRegCompInv should return a
    55  // positive number, but can return 0 even with non-zero y due to underflow.
    56  func GammaIncRegCompInv(a, y float64) float64 {
    57  	return cephes.IgamI(a, y)
    58  }