Numerical integration over a circle contour [duplicate]

This question already has an answer here:

I want to numerically integrate the following function

$$f(p) = \frac{1}{2\pi i}\int_{\Gamma}\frac{1}{p}\exp\left(\frac{a^{2}}{2}\frac{1}{p}+\frac{b^{2}}{2}p\right)dp$$

where the contour $\Gamma$ is a circle with radius $r$ less than unity and let a and b to be unity

I wrote it like this on Mathematica, but I don't know a possible way to write the integral limits

NIntegrate[1/(2*Pi*I*p)*Exp[1/(2*p) + 1/2*p], {p, ,]

marked as duplicate by Jens, user9660, m_goldberg, MarcoB, Sjoerd C. de VriesJun 20 '16 at 18:19

• Welcome to MSE. This link may be helpful: mathematica.stackexchange.com/a/34090/1997 – ubpdqn May 19 '16 at 3:05
• Okay, try making the substitution $p=r\exp(i t)$, and take the limits from $0$ to $2\pi$. – J. M. will be back soon May 19 '16 at 3:13
• Thanks a lot. It's working, please add it as an answer – mostafa sayed May 19 '16 at 7:57
• The sub-section "Applications" of the section "Examples" in NIntegrate's function page has examples on doing integrals over lines, surfaces, volumes, and regions. – Anton Antonov May 19 '16 at 15:26
• Although this is about numerical integration, the maths is exactly the same as in Complex line integral. In particular, you can use my answer there to do the integral simply in the form f[p_]:=1/p Exp[1/(2 p)+1/2 p]; (1/(2 Pi I)) contourIntegrate[ Cos[t]+I Sin[t], f,{t,0,2 Pi}]. The answer is BesselI[0,1]. – Jens Jun 20 '16 at 5:15

Edit: Posted for review.. I'm not sure if this is correct.

making the substitution per comments, p=r Exp[I t] so that dp == r I Exp[I t] dt == I p dt :

With[{r = 2, a = 1, b = 1}, (1/ (2 Pi I)) NIntegrate[
I Exp[a^2/(2 (r Exp[I t])) + b^2/2 (r Exp[I t])],
{t, 0 , 2 Pi}]]

1.26607 + 4.24074*10^-15 I

(Note this agrees with the BesselI[0, 1] result per comments)

for the record I first though we could use the region integrate capability:

With[{r = 2, a = 1, b = 1},
(1/ (2 Pi I)) NIntegrate[
1/((x + I y))*Exp[a^2/(2*(x + I y)) + b^2/2*(x + I y)],
Element[{x, y}, Circle[{0, 0}, r]]]]

2.82716*10^-16 - 1.13032 I

which is the same result as we get with the first sub but with dp/dt = r:

With[{r = 2, a = 1,  b = 1},
(1/ (2 Pi I)) NIntegrate[
1/(Exp[I t])*Exp[a^2/(2*(r Exp[I t])) + b^2/2*(r Exp[I t])],
{t, 0 , 2 Pi}]]

7.0679*10^-17 - 1.13032 I

• Note that BesselI[1,1] is approximately $0.565159 \approx \frac{1}{2}( 1.13032)$. So your second and third expressions are not giving the same result, probably because the two integrals aren't over the same circle ($r = 2$ for the second, $r = 1$ for the third.) – Michael Seifert May 19 '16 at 18:15
• right, the first two run with r=1 agree with the BesselI result for r=1 ( That is they are all 3 right or all three wrong ! ) – george2079 May 19 '16 at 18:46
• See this page for what looks to be the exact integral in question (with $a = b = 1$ in our integral and $z = 1, n = 0$ in that expression.) Note that this implies that the correct answer should be $I_0(1) \approx 1.26607$, which suggests to me that the last answer is the correct one and the first three are wrong. (Not sure why, though.) – Michael Seifert May 19 '16 at 19:03
• On further reflection, I suspect that's what's happening here is that the integration over regions implicitly assumes a line element of the form $dl = \sqrt{dx^2 + dy^2}$ (or $dl = \sqrt{dr^2 + r^2 \, d\theta^2}$) as we integrate around the curve. But for a complex integral in the complex plane, we should be using $dl = dx + i dy$ instead (or $dl = e^{i\theta} dr + i r e^{i\theta} \, d\theta$.) – Michael Seifert May 19 '16 at 19:18
• @MichaelSeifert i think that's right, reordered the results in the answer. – george2079 May 20 '16 at 16:53