If making the integration easier is the goal, consider using the residue theorem. First, here's how to do the integral the hard way:
By Definition of Contour Integral
We start by defining the function and the parameters of the rectangular contour. Then we calculate the path integral from the first corner of the rectangle to the second. On this path we have $dz = dx$, so it's straight forward. On the second path, we have $dz = i dy$, so we have to multiply the integral by I
. The third and fourth legs are similar. We use NIntegrate
, because the result provided by Integrate
is messy. Here's the code, and the results.
f[z_] := Cos[z]/((z + 2)*(z + I) (z - 2 I))
{y1, y2, x1, x2} = {-2, 3, -3/2, 3/2};
{ NIntegrate[f[x + I y] /. y -> y1, {x, x1, x2}],
I NIntegrate[f[x + I y] /. x -> x2, {y, y1, y2}],
NIntegrate[f[x + I y] /. y -> y2, {x, x2, x1}],
I NIntegrate[f[x + I y] /. x -> x1, {y, y2, y1}]
} // Total
(*0.677153 - 2.61625 I *)
By The Residue Theorem
The residue theorem says for any closed path we can calculate the contour integral by adding the residues of the function at any singular points enclosed by the path and multiplying by $2\pi i$. We don't need to deform the path when we work with the residues. Our function has 3 singular points, but only two of them are enclosed by the rectangular path. Those points are $z_1$ and $z_2$ in the following code.
z1 = -I; z2 = 2 I;
r1 = Residue[f[z], {z, z1}];
r2 = Residue[f[z], {z, z2}];
2 π I (r1 + r2) // Simplify
% // N
(* (-(1/10) + I/30) π ((2 + 2 I) Cosh[1] - (2 - I) Cosh[2]) *)
(* 0.677153 - 2.61625 I *)
Here we get a closed form solution that is not too messy.