Consider the function


it is a well-known fact that this function has simple poles at half integer values of the argument x=1/2,3/2,5/2,7/2... Say I want to numerically integrate this function from zero to infinity. I am aware that the Principal Value method is appropriate to handle numerical integrals whose integrands blow up at certain points. In this case I have an infinity of poles, and I want to know if there is an elegant way of telling Mathematica where they are instead of doing it by hand like I do it in the next line


So, how can I implement this more elegantly?


1 Answer 1


Maybe you can just evaluate the principal value by hand, by choosing a contour above and below the line of poles:

    NIntegrate[Gamma[1/2-x], {x, 0, I, Infinity}] +
    NIntegrate[Gamma[1/2-x], {x, 0, -I, Infinity}]

-0.792706 + 0. I


Just for fun, we can use the above approach to compute the sum of the residues of Gamma[1/2-x]:

    NIntegrate[Gamma[1/2-x], {x, 0, -I, Infinity}] - 
    NIntegrate[Gamma[1/2-x], {x, 0, I, Infinity}]
) / (2 Pi I)

-0.367879 + 0. I

or the equivalent:

NIntegrate[Gamma[1/2-x], {x, 0, -I, Infinity, I, 0}] / (2Pi I)

-0.367879 + 0. I

Now, the residues of Gamma[1/2-x] can be computed using SeriesCoefficient:

res[n_] = SeriesCoefficient[

(-1)^(1 - n)/n!

The sum is then given by:

Sum[res[n], {n, 0, Infinity}] //N


in agreement with the NIntegrate approach.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.