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}]
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 *)
Answer
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 !
Comments
Post a Comment