# Having problems integrating a function of a complex variable [closed]

I've tried to calculate the integral

And I got the result $16i \pi ^3$.

I wanted to check my calculation, so I ran this code in Mathematica:

With[{z = 3 π Exp[I th]}, NIntegrate[z^2/(Exp[z] - 1)^2, {th, 0, 2 π}]]

which gave me the answer $18.8496$ (Which is $6\pi$).

I couldn't find any mistakes in my calculation, so I gave Wolfram the following code which calculates the integral with the residue theorem and with poles at $\pm 2\pi i$

N[2 π I
(Residue[z^2/(Exp[z] - 1)^2, {z, 2 Pi I}] +
Residue[z^2/(Exp[z] - 1)^2, {z, -2 Pi I}])]

And that code gave me $0. + 496.1 i$, which is the numerical representation of my result for the integral.

Does someone know why do the straight forward approach didn't work?

## closed as off-topic by Artes, MarcoB, Coolwater, Henrik Schumacher, C. E.Feb 1 '18 at 17:04

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Artes, MarcoB, Coolwater, Henrik Schumacher, C. E.
If this question can be reworded to fit the rules in the help center, please edit the question.

• Isn't there a pole at $z = 0$? – David G. Stork Jan 22 '18 at 21:50
• The pole at $z=0$ isn't really a pole - It's a removable singularity so it doesn't add to the residue – DeadlosZ Jan 22 '18 at 21:51
• You forgot dz = 3 Pi I Exp[I th] dth – Carl Woll Jan 22 '18 at 21:54
• Why are right, but adding * 3 Pi I z still doesn't give the correct answer – DeadlosZ Jan 22 '18 at 21:56
• nevermind. no need for another 3 Pi there. problem solved! – DeadlosZ Jan 22 '18 at 21:57

You forgot the integration measure:

With[{z=3 π Exp[I θ]},
NIntegrate[z^2/(Exp[z]-1)^2 D[z, θ], {θ, 0, 2 π}]
]

2.27374*10^-13 + 496.1 I

An alternate approach is to just give NIntegrate a contour:

NIntegrate[z^2/(Exp[z]-1)^2, {z, 1, 3 π I, -1, -3 π I, 1}]

1.32365*10^-11 + 496.1 I

• Yap. that solved it. Thank you very much! – DeadlosZ Jan 22 '18 at 21:58

Appropriate parametrization involves $\;dz=\frac{d z(\phi)}{d \phi} d \phi = 3\pi i \exp(i \phi) d \phi$ which has been omitted in the original post. Numeric calculation yields a correct result, while the system can't integrate it symbolically with such a parametrization. Using Residue we can find an exact symbolic result. In the comments there were some imprecise statements so we demonstrate the full reasoning. There is a beautiful result in complex analysis: Residue theorem being a simple consequence of the Cauchy integral theorem, i.e. for e meromorphic function in a simply connected open subset $U$ of the complex plane we have $$\int_{\gamma} f(z)dz=2 \pi i \sum_{a \in A} Res_{z=a}(f(z))$$ where $A$ denotes the set of residual points in a region enclosed by $\gamma$.

For the problem at hand: $f(z)=\frac{z^2}{(\exp(z)-1)^2}$ and $\gamma=\{x \in U: |x|=3\pi \}$

Let's find all residual points:

A = z/.{ToRules @ Reduce[(Exp[z] - 1)^2 == 0 && Abs[z] <= 3 π , z]} // Flatten
{0, -2 I π , 2 I π }

and finally the contour integral is

Total[2π I Residue[z^2/(Exp[z] - 1)^2, {z, #}] & /@ A] // Simplify
16 I π^3

With another approach which uses symbolic calculation, Mathematica 11.2 takes a bit (~10 sec.) to yield a silightly involved expression:

int = Integrate[ z^2/(Exp[z] - 1)^2, {z, 3π , 3I π , -3π , -3I π , 3π }];

which can be approximated (simplified) (as observed by Bob Hanlon) with

RootApproximant[int/π^3] π^3
16 I π^3

Here we demonstrate different contours of integration we've discussed

ContourPlot[{Re[(Exp[z] - 1)^2] == 0, Im[(Exp[z] - 1)^2] == 0,
Abs[z] - 3 Pi == 0} /. z -> x + I y // Evaluate,
{x, -3.5 π, 3.5 π}, {y, -3.5 π, 3.5 π},
Epilog -> {Red, PointSize[0.02], Point[ReIm[A]], Dashed, Thick,
Purple, Line[{{3π, 0}, {0, 3π}, {-3π, 0}, {0, -3π}, {3π, 0}}]},
PlotLegends -> Placed["Expressions", Right],
ContourStyle -> {{Thick, Darker@Green}, {Thick, Cyan}, {Dashed, Thick, Orange}}]

For various examples of appropriate parametrizations, see e.g.

Paths integrals in the complex plane

There were many different helpful posts on this site, however such an amazing subject as complex analysis deserves repetitions, since repetitio est mater studiorum.

• +1. Your definition of A should include A = z /. ... to convert the rules to values. int can be simplified with RootApproximant[int/Pi^3] Pi^3 – Bob Hanlon Jan 24 '18 at 13:56
• @BobHanlon Thanks, formerly I've written in the notebook something different than in the post. – Artes Jan 24 '18 at 15:46