Questions tagged [gamma-function]

Anything related to the mathematical gamma function, also known as generalized factorial function.

Anything related to the mathematical gamma function, also known as generalized factorial function.

See Wikipedia page on gamma function.

72 questions
3
votes
1 answer

I am trying to solve a function in Matlab: digamma(x) =C

For example, C=0, solve('psi(x)=0') ans = -226.83295306016122662496413158295 psi(ans) ???Error using ==> psi Input must be single or double. I cannot get the right answer
2
votes
1 answer

Gamma Function in R

I am trying to implement a gamma function from scratch using the following rules: If z is equal to 1 we return 1; List item gama(z) (using the recursion of the function) (z-1)*gamma(z-1); If z is a natural number then we return the factorial of…
bSwizzle
  • 73
  • 8
2
votes
2 answers

scipy.special.gammainc does not accept negative input

I have used SageMath to symbolically integrate an expression. The result contains a gamma function with two input parameters: gamma(-1, 2*((x - xp)^2 + (y - yp)^2)/s^2) Apparently this is called an incomplete gamma function. Now I want to use this…
Numaerius
  • 383
  • 3
  • 10
2
votes
1 answer

Why is this log gamma numba function slower than scipy for large arrays, but faster for single values?

I have a function to calculate the log gamma function that I am decorating with numba.njit. import numpy as np from numpy import log from scipy.special import gammaln from numba import njit coefs = np.array([ 57.1562356658629235,…
PyRsquared
  • 6,970
  • 11
  • 50
  • 86
2
votes
1 answer

How do I get the value of gamma function in Python for large complex argument?

I am trying to compute the value of Beta function for complex argument. The method scipy.special.beta does not accept complex argument, so I defined instead beta = lambda a, b: (gamma(a) * gamma(b)) / gamma(a + b) It works fine for small values,…
zyy
  • 1,271
  • 15
  • 25
2
votes
1 answer

Bayesian Gamma regression, what is the correct link function?

I'm trying to do a bayesian gamma regression with stan. I know the correct link function is the inverse canonical link, but if i dont use a log link parameters can be negative, and enter in a gamma distribution with a negative value, that obviously…
2
votes
1 answer

Upper Incomplete Gamma Function of order 0 in scipy

I am trying to implement the upper incomplete gamma function of order zero in Python. Normally we use gammaincc function but according to the docs,it's defined only for positive a. Is there any way to implement it in python for a=0 case? Thanks.
Prav001
  • 343
  • 1
  • 5
  • 12
2
votes
1 answer

Gamma function returns unstable value?

Gamma function should not take any negative value as an argument. Look at the code below where strange thing happens. Is this some problem with R? I was using function optim to optimize some function containing: gamma(sum(alpha)) with respect to…
Xinming
  • 117
  • 1
  • 6
2
votes
2 answers

Arbitrary precision gamma function

I'm implementing an arbitrary precision arithmetic library in C++ and I'm pretty much stuck when implementing the gamma function. By using the equivalences gamma(n) = gamma(n - 1) * n and gamma(n) = gamma(n + 1) / n, respectively, I can obtain a…
borchero
  • 5,562
  • 8
  • 46
  • 72
2
votes
0 answers

Prevent scipy.optimization routine from evaluating gamma function at negative integers

Issue: Prevent scipy brute optimization routine (or any opt routine for that matter) from evaluating a function with negative integers. The overall function I am trying to optimize uses a gamma function which is undefined for negative integers.…
Doug
  • 209
  • 2
  • 9
  • 19
2
votes
1 answer

Gamma density plot: dgamma working while own function returning error

I am trying to plot a Gamma density function for the parameters (shape) alfa=3457 and (rate) beta=84. If I do this using: curve(dgamma(x,shape=3457,rate=84),from=35,to=50,xlab="posterior theta",ylab="density") everything works out just fine and I…
2
votes
1 answer

How could I enhance the speed of this gamma function and complex numbers - related code?

Context: I am trying to make a very simple gamma function fractal plotting using Python and sympy, initially a very simple version to understand how it works (two mapping colors based on the value of counter=0 or 1). Basically the code (below)…
iadvd
  • 179
  • 1
  • 2
  • 12
2
votes
1 answer

how to solve a distribution parameters from its mean and variance

I update the OP so that the original question can be solved by solving the following equations. integral_from_0_N of (x * f(x)) dx = constant // here , constant > 0 , N > 0 where f(x) = g(j,k) * (x/k)^(j-1) * exp(-x/k) // here, k > 0 , j >…
2
votes
1 answer

Cumulative distribution function with Gamma Function in Python

I am dealing with the Schechter Luminosity function that looks like this: phi(L)dL = norm. Factor * (L/Lstar)^(a) * exp (L/Lstar) d(L/Lstar) Say, L/Lstar is l. The analytic solution to its cumulative distribution function of is given by the gamma…
user3014593
  • 231
  • 1
  • 2
  • 5
1
vote
1 answer

How can fix the error"Cannot convert expression to floating python?

#This is my code import numpy as np import sympy as sp n=3 y = [sp.symbols('y%d' % i) for i in range(8*n-4)] #x=sp.symbols('x:n') x=np.zeros((1,n)) for i in range(n): x[i]=sp.gamma(y[i]) print(x) I need x[i] to continue the code, but…