Message Boards Message Boards

2
|
6165 Views
|
4 Replies
|
5 Total Likes
View groups...
Share
Share this post:
GROUPS:

Different results of definite integral over complex exponential.

Posted 12 years ago
We are currently using Mathematica 9.0 and came across the problem, that in certain situations, Mathematica will give different results for the same definite integral. Here is a minimal working example
Integrate[Abs[Cos[?]+??Sin[?]]^2,{?,0,2??}]
Integrate[Abs[Exp[? ?]]^2,{?,0,2??}]
The first integral gives zero, while the second one holds the correct result 2*pi. Using FullSimplify gives the correct result but is too time consuming for larger expressions.
I would appreciate any help concerning this issue, as these functions are rather often used in our codes here and this really questions the reliability of Integrate and/or Abs.

Thanks!
POSTED BY: Andreas B.
4 Replies
Posted 12 years ago
Scary...  Same thing in v8. It seems to only happen when the region of integration is [0,2Pi]  or [-2Pi, 0]:
Cases[
ParallelTable[
  {i Pi, (i + 2) Pi, Integrate[ Abs[ Cos[x] + I Sin[x]]^2, {x, i Pi, (i + 2) Pi}]},
  {i, -100, 100}],
{_, _, Except[2 Pi]}]
(* {{-2 Pi, 0, 0}, {0, 2 Pi, 0}} *)

Perhaps you can change your region of integration as a workaround.
POSTED BY: Simon Schmidt
Posted 12 years ago
Thank you very much for your reply. If the integration region is not exactly [0,2 pi], Mathematica gives the correct result indeed.
Integrate[Abs[Cos[?]+??Sin[?]]^2,{?,0,1.9999999?}]?
Integrate[Abs[Cos[?]+??Sin[?]]^2,{?,10-9,2??}]
But this takes an unreasonably high amount of computation time in comparison to the procedures above. Additionally as this is a really common integration region, it would be interesting to know if there are other cases in which this bug arises.
POSTED BY: Andreas B.
Posted 12 years ago
!!!DO NOT USE, MAY BREAK MANY THINGS. WAIT FOR OFFICIAL FIX!!!
With that disclaimer out of the way:

I got curious where this happened and Spelunked a bit.
The problem arises in
Integrate`ImproperDump`Dispatcher[f_, {x_, 0, 2 PI}]
where the function is decomposed into a polynomial in Cos and Sin whose coefficients get improperly transformed for complex values. (1^2 + I^2 = 0)

I decided to drop that downvalue from Dispatcher to see what happens:
 (* Make sure definitions are loaded *)
 Integrate[Abs[Cos[x] + I Sin[x]]^2, {x, 0, 2 Pi}]
 
 dw = DownValues[Integrate`ImproperDump`Dispatcher];
 pos = Position[dw,
         HoldPattern[Integrate`ImproperDump`Dispatcher[f_, {x_, 0, 2 Pi}]]
       ][[1, 1]];
 dw = Drop[dw, {pos}];
 DownValues[Integrate`ImproperDump`Dispatcher] = dw;

Integrate[Abs[Cos[x] + I Sin[x]]^2, {x, 0, 2 Pi}]
(* 2 Pi :) *)

To get back to normal just restart the kernel
POSTED BY: Simon Schmidt
Posted 12 years ago
Great, this seems to solve the issue. With your permission, I would send this to the support, so it gets fixed in the next release.
POSTED BY: Andreas B.
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract