2

Say I have a function $f$ of $n$ complex variables, $\{ z_i \}_{i=1}^{i=Nc}$. And then I want to contour integrate the expression such that for each $z_i$ its an integration on an unit circle about the origin in the complex plane:

$$\oint_{\cal C}\cdots \oint_{\cal C} f(z_1,\cdots, z_n) d z_1 .. d z_n$$

I would guess that in some sense this should pick out the "residue" of the n-dimensional complex function $f$. (...I am not exactly sure of a residue interpretaton for such contour integrations on the complex plane...)

I would like to know how to set this up in Mathematica (..hopefully as a residue finding problem..)

chris
  • 22,860
  • 5
  • 60
  • 149
user6818
  • 1,171
  • 1
  • 12
  • 27

1 Answers1

6

Let us use the ContourIntegrate function which I think I pinched this function somewhere on this site

ContourIntegrate[f_, par : (z_ -> g_), {t_, a_, b_}] := 
          Integrate[Evaluate[(f /. par) D[g, t]], {t, a, b}]

Let's check it

ContourIntegrate[1/x, x -> Exp[I t], {t, 0, 2 Pi}] - 2 Pi I Residue[1/x, {x, 0}]
(* 0 *)

or just for fun on this path

 ParametricPlot[Exp[I t] (1 + Exp[12 I t]/4) // {Re[#], Im[#]} &, {t, 0, 2 Pi}]

Mathematica graphics

 ContourIntegrate[1/(x - 1/2), x -> Exp[I t] (1 + Exp[12 I t]/4), {t, 0, 2 Pi}]

  (* 2I Pi *)

As @J.M. mentions, you can chain contours, but you must proceed one contour at a time

ContourIntegrate[ContourIntegrate[1/(x u), x -> Exp[I t],{t, 0, 2 Pi}],u ->Exp[I t], {t, 0, 2 Pi}]

 (* -4Pi^2 *)

and so on...

  ContourIntegrate[ContourIntegrate[ContourIntegrate[1/(x u v), x -> Exp[I t],{t, 0, 2 Pi}],
          u ->Exp[I t], {t, 0, 2 Pi}],v ->Exp[I t], {t, 0, 2 Pi}]

  (* -8I Pi^3 *)

EDIT

Since I am (personally) interested in a numerical solution, let's see how it can be done numerically as well. Let's define

 NContourIntegrate[f_, par : (z_ -> g_), {t_, a_, b_}] := 
        NIntegrate[Evaluate[D[g, t] (f /. par) /. t -> t1], {t1, a, b}]

so that

 NContourIntegrate[1/x, x -> Exp[I t], {t, 0, 2 Pi}] - 2 Pi I Residue[1/x, {x, 0}]

(* 0. *)

Or, to consider a wikipedia example, let us integrate $\frac{1}{(z^2+1)^2}$ over the path

 pw[t_] = Piecewise[{{2 Exp[I t], t < Pi}, {-2 + 4 (t - Pi)/Pi, t > Pi}}];
 ParametricPlot[pw[t] // {Re[#], Im[#]} &, {t, 0, 2 Pi}]

Mathematica graphics

 NContourIntegrate[1/(x^2 + 1)^2, x -> pw[t], {t, 0, 2 Pi}] // Chop
 ContourIntegrate[1/(x^2 + 1)^2, x -> pw[t], {t, 0, 2 Pi}]//FullSimplify

 (* 1.5708 and Pi/2 *)

Finally, moving to the multivariate case, if I define

 Clear[h]; h[u_?NumberQ] := NContourIntegrate[1/x/u, x -> Exp[I t], {t, 0, 2 Pi}]

then

 NContourIntegrate[h[u], u -> Exp[I t], {t, 0, 2 Pi}]

yields correctly

  (* -39.47 =N[-4 Pi^2] *)

And more generally

 Clear[h1];h1[u_?NumberQ, v_?NumberQ] := 
       NContourIntegrate[1/(x - 1/2)/(u + 1/2)/v, x -> Exp[I t], {t, 0, 2 Pi}];
 Clear[h2]; h2[v_?NumberQ] := 
       NContourIntegrate[h1[u, v], u -> Exp[I t], {t, 0, 2 Pi}]

 NContourIntegrate[h2[v], v -> Exp[I t], {t, 0, 2 Pi}] + I 8  Pi^3

 (* 0. *)
chris
  • 22,860
  • 5
  • 60
  • 149
  • Thanks for the answer but this function ``ContourIntegrate" doesn't seem to exists per se. Can you tell me where is that to be accessed? – user6818 Oct 29 '12 at 02:59
  • I see a definition of your function here, http://mathematica.stackexchange.com/questions/13734/symbolic-integration-in-the-complex-plane . But it seems that you are actually explicitly integrating in this case - then you aren't using the residue theorem really..right? Can this be scaled to large values of $Nc$ ? – user6818 Oct 29 '12 at 03:08
  • @user6818 the function ContourIntegrate is defined in my answer on the first line ContourIntegrate[f_, par : (z_ -> g_), {t_, a_, b_}] := Integrate[Evaluate[(f /. par) D[g, t]], {t, a, b}]. – chris Oct 31 '12 at 08:59
  • 1
    ContourIntegrate has been built-in in v13.3, perhaps it's better to update the answer a bit :) . – xzczd Jun 27 '23 at 05:44
  • @xzczd I didn't know this I don't have 13.3. WRI should pay me some royalties for integrating my SE questions into their software over the years :-) – chris Jun 27 '23 at 06:16