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