6
$\begingroup$

Context

While answering this question, I defined (symbolic and numerical) path integrations as follows

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

I also defined a piecewise contour

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

Mathematica graphics

While checking these routines on wikipedia examples, I tried numerically

 Table[NContourIntegrate[Exp[I i x]/(x^2 + 1), x -> pw[t, 2], {t, 0, 2 Pi}], {i, 2, 5}] // Chop (* {0.425168,0.156411,0.0575403,0.0211679} *) 

which corresponds accurately to (see example II for Cauchy distributions)

Table[Exp[-i] Pi, {i, 2, 5}] // N 

On the other hand, the symbolic integration

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

returns 0.

Question

What am I doing wrong?

Attempts

Example I and III work ;-)

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

and

NContourIntegrate[1/I/x/(1 + 3 ((x + 1/x)/2)^2), x -> Exp[I t], {t, 0, 2 Pi}]//Chop ContourIntegrate[1/I/x/(1 + 3 ((x + 1/x)/2)^2), x -> Exp[I t], {t, 0, 2 Pi}] (* 3.14159 Pi *) 
$\endgroup$
8
  • 1
    $\begingroup$ For Example II, with exactly the same code as you have (except that I changed your x more suggestively to z), Mathematica 8.0.4 is giving me result Pi/E. This agrees with the answer provided by the Residue Theorem. $\endgroup$ Commented Oct 27, 2012 at 15:39
  • $\begingroup$ @murray uhm... it seems you are right.. $\endgroup$ Commented Oct 27, 2012 at 15:43
  • $\begingroup$ The answer you got from ContourIntegrate in Example IIIa is correct -- and is the same, except for form, as the answer $\pi \sqrt{2}/4$ obtained from substitution and the Residue Theorem as in the wikipedia page you cite. $\endgroup$ Commented Oct 27, 2012 at 15:43
  • $\begingroup$ @murray right again... ghosh I guess I am out of my mind.. $\endgroup$ Commented Oct 27, 2012 at 15:48
  • 2
    $\begingroup$ But you have a nicely defined contour integration routine. Note that it's certainly not necessary to pack parameterization of the entire contour into a single Piecewise function; that just forces one do some contortions to get the t-value at the end of one piece to match up with the t-value at the start of the second piece. It seems it would be simpler to separately parameterize the semicircle and the $x$-axis and evaluate the contour integrals of both; then just add. $\endgroup$ Commented Oct 27, 2012 at 15:54

1 Answer 1

8
$\begingroup$

The problem lies with the fact that my init.m file has

 SetOptions[Integrate, GenerateConditions -> False] 

If I use

 SetOptions[Integrate, GenerateConditions -> True] 

or define

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

the discrepency vanishes.

I guess this makes this question too narrow to be of general interest!

In any case, the bring home message is don't do complex integration without paying attention to branch-cuts !

$\endgroup$
1
  • 4
    $\begingroup$ No, I don't think this is too narrow an issue: the post might help somebody else with a mysterious result! $\endgroup$ Commented Oct 27, 2012 at 19:22

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.