### upper incomplete gamma function in fenics

185

views

0

Does FEniCS/dolfin have a built-in function for calculating the upper incomplete gamma function?

The general form of the function is

\begin{equation}

\Gamma(a, x) = \int_{x}^{\infty} t^{a-1} e^{-t} dt

\end{equation}

The general form of the function is

\begin{equation}

\Gamma(a, x) = \int_{x}^{\infty} t^{a-1} e^{-t} dt

\end{equation}

Community: FEniCS Project

### 1 Answer

1

Not that I know of. The UFL manual is here:

https://media.readthedocs.org/pdf/fenics-ufl/latest/fenics-ufl.pdf

and Ctrl+F "gamma" doesn't find anything relevant. Depending on your purpose, you might be able to get away with wrapping SciPy's function in a user-defined Expression. For example, if $a$ is a constant, and $x$ is a spatial coordinate, you could do something like this:

Thanks David.

mpmath also has the gammainc function built-in, and is not normalized like scipy.

https://media.readthedocs.org/pdf/fenics-ufl/latest/fenics-ufl.pdf

and Ctrl+F "gamma" doesn't find anything relevant. Depending on your purpose, you might be able to get away with wrapping SciPy's function in a user-defined Expression. For example, if $a$ is a constant, and $x$ is a spatial coordinate, you could do something like this:

```
from dolfin import *
from scipy.special import gammaincc as scipyGamma
mesh = UnitIntervalMesh(10)
a = 1.0
class UpperIncompleteGamma(Expression):
def eval(self,values,x):
values[0] = scipyGamma(a,x[0])
# can be used in UFL
gamma = UpperIncompleteGamma(degree=2)
# test:
x = 1.234
fenicsGamma = [0.0,]
gamma.eval(fenicsGamma,Point(x))
print("scipy: "+str(scipyGamma(a,x)))
print("fenics: "+str(fenicsGamma[0]))
```

EDIT: Note that SciPy's version is "regularized", if that matters:

https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.gammaincc.html#scipy.special.gammaincc

It looks like a normalizing factor of $\Gamma(a)$.

mpmath also has the gammainc function built-in, and is not normalized like scipy.

written
5 months ago by
Soroushr

Please login to add an answer/comment or follow this question.

`\(`

to open and`\)`

to close.