Why contour integral is different from an approximate contour summation for complex functions with poles

complex integrationcomplex-analysisnumerical methods

I am trying to calculate a contour integration of the form
$$
\frac{1}{2\pi i}\oint\limits_c f(z)\: dz
$$

numerically. I know the integral is the same as the sum over all the residues of the function on the poles within the contour $c$
$$
\frac{1}{2\pi i} \oint\limits_c f(z)\: dz = \sum_{z \in I} Res(f(z),z)
$$

$I$ is the set of poles within the contour $c$.

For simple poles, the residues can be calculated in a fairly simple manner like given in the answer, but for higher-order poles, this becomes very hard numerically as it involves higher-order
derivatives of $z$ (is there any other simple way without derivatives?) and calculating the contour integration directly rather seems like less of a daunting task to do. For example, say
$$
f(z) = 1/z
$$

The pole is at $z=0$ with residue $1$. So $\frac{1}{2\pi i} \oint\limits_c f(z)\: dz = 1$.
I am choosing a dimond shaped contour centered at the origin like this,

enter image description here

And doing numerical integration in Mathematica

NIntegrate[1/(2 Pi I) 1/z, {z, 1, I, -1, -I , 1}]

The result is $ 0.9999999999999979 – i\: 2.7755575615628914\times 10^{-17} \approx 1 $ as expected.

Till now everything is fine, the numerical result matches up to the analytical result up to machine precision.

Now, I am trying to do the same but using summation on the contour. I am approximating the contour integral as
$$
\frac{1}{2\pi i} \oint\limits_c f(z)\: dz \approx \frac{dz}{2 \pi i}\sum_{z \in c} f(z)
$$

I am parametrizing the curve as $p(t)$ as $t$ goes from $0 \to 1$ the contour is traversed once.
$$
p(t) =
\begin{cases}
1-4t+i\:4t &\mbox{ } 0 \leq t \leq \frac{1}{4} \\
1-4t+i\:(2-4t) &\mbox{ } \frac{1}{4} \leq t \leq \frac{1}{2} \\
4t-3+i\:(2-4t) &\mbox{ } \frac{1}{2} \leq t \leq \frac{3}{4} \\
4t-3+i\:(4t-4) &\mbox{ } \frac{3}{4} \leq t \leq 1
\end{cases}
$$

The summation is
$$
\frac{dz}{2 \pi i} \sum_{t=0}^{1} f(p(t)) =
\frac{dz}{2 \pi i} \sum_{t=0}^{1} \frac{1}{p(t)}
$$

path[t_] = Piecewise[{{{1 - 4*t, 4*t}, 0 <= t <= 1/4}, {{1 - 4*t, 2 - 4*t}, 
   1/4 <= t <= 1/2}, {{-3 + 4*t, 2 - 4*t}, 1/2 <= t <= 3/4}, 
     {{-3 + 4*t, -4 + 4*t}, 3/4 <= t <= 1}}, 0]

dz = 0.0001;
data = Sum[
  zi = #[[1]] + I #[[2]] &@path[t];
  dz*1/(2 Pi I) 1/zi
  , {t, 0, 1, dz}]

the path function is the aforementioned $p(t)$

And the result in this case is $-6.009953532397927\times 10^{-18} – i \: 0.00001591549430919666 $. As I make dz even smaller the result doesn't improve much. This way off from the actual calculation. The numerical integration does much more than a vanilla sum, but as the spacing decreases, I would think the results would match.

NIntegrate in Mathematica by default uses some adaptive non-uniform sampling algorithm that samples the function at certain points and does a recursive bisection followed by a summation around that point until convergence up to certain decimal order is achieved.

Why are the results so much different?

Best Answer

Let $\gamma: [0, 1] \to \Bbb C$ be a parametrization of the contour $c$. For a “sufficiently fine” partition $0 = t_0 < t_1 < \cdots < t_n = 1$ we have $$ \int_c f(z) \, dz = \int_0^1 f(\gamma(z)) \gamma'(z) \, dz \approx \sum_{j=1}^{n} f(\gamma(t_j)) \gamma'(t_j)(t_j - t_{j-1}) \\ \approx \sum_{j=1}^{n} f(z_j) (z_j - z_{j-1}) $$ where $z_j = \gamma(t_j)$. In particular, the “increments” $z_j - z_{j-1}$ are not constant along the curve.

Related Question