# Problem with Gamma function

(0.17730992497288517, 2.7755575615628914e-17)
If ‘t’ is known, then this works every time. Gamma in Julia seems to be a problem. What am I doing wrong?

Can’t really tell what the error is you’re describing since you’ve not shown any of the details, but I think you are wanting to do using SpecialFunctions to get the gamma function.

4 Likes

Hi and welcome to the Julia discourse.

Could you maybe provide code that is not working? As Daniel wrote, you might have (just) added a package (installed it on hard drive) but not loaded it (using).

Two formatting tips: You can put code in backticks  to have inline code (or three of them to have a code block) – and you can also put math in $...$ to have it rendered like $\alpha$ renders nicely as \alpha.

4 Likes

I am not an expert on gamma functions, but it seems that your formulation is not correct.
First, the integration in your formula is over z whereas according to Gamma function - Wikipedia the integration is over t. Moreover, you are integrating between 0 and 1 and again the formula I know integrates between 0 and \infty.
For your original question, as other have already pointed out, this should work:

using SpecialFunctions
res = gamma(1) # = 1
res = gamma(0.5) # = 1.77


Apart from the issues already highlighted by others, to me it seems you want gamma to be a function, so that you could write e.g. gamma(1). But then you’d need

gamma = t -> first(quadgk(z -> t^(z - 1) * ..., ...))


(well actually, gamma = z -> first(quadgk(t -> ..., ...)) as pointed out by Rudi79).
In your current definition gamma is just a float which can only be evaluated if your t` was defined prior, as you point out.

1 Like

Thank you for the answers. You are correct about choosing z, but it did not work for some reason. I will try it again.