In[1]:=
Integrate[Sqrt[2-Sin[x]],{x,1,4}]
Out[1]= (*** Wrong answer ***)
-2*EllipticE[(-4 + Pi/2)/2, -2] +
2*EllipticE[(-1 + Pi/2)/2, -2] +
4*EllipticF[I*ArcSinh[1/Sqrt[2]], -2]
In[2]:=
Integrate[Sqrt[2-Sin[x]],{x,1,Pi/2,4}]
Out[2]= (*** Right answer ***)
-2*EllipticE[(-4 + Pi/2)/2, -2] +
2*EllipticE[(-1 + Pi/2)/2, -2]
-------------------------------
Then Bob Hanlon replied:
I cannot find any documentation in the on-line Help nor at
http://www.dot.net.au/~elisha/ersek/Tricks.html for use of the additional
(third of four) argument in the iterator in Integrate (Pi/2 in this case).
What is this argument doing and where is its use documented?
-------------------------------
ANSWER:
The documentation for NIntegrate says:
"NIntegrate[f, {x,x0,x1, ... ,xk}] tests for singularities at each of the
intermediate points xi. If there are no singularities, the result is
equivalent to an integral from x0 to xk. You can use complex numbers xi to
specify an integration contour in the complex plane."
Although the documentation doesn't say so it seems this applies to Integrate
as well. When I wrote the previous email I was thinking of the line above,
but didn't remember that I read this in the documentation for NIntegrate not
Integrate.
Below I give convincing evidence that this works with Integrate. Here I
integrate along a closed contour in the complex plane. Notice I get the
same answer when I apply a theorem related to Residues.
In[1]:=
Integrate[1/(z^2+4),
{z,-1,1,1+3I,-1+3I,-1}]//FullSimplify
Out[1]=
Pi/2
In[2]:=
(2 Pi I)Residue[1/(z^2+4),{z,2I}]
Out[2]=
Pi/2
I think the documentation for Integrate should be changed to mention this
feature.
--------------------------------
Regards,
Ted Ersek
For Mathematica tips, tricks see
http://www.dot.net.au/~elisha/ersek/Tricks.html
>I think the documentation for Integrate should be changed to mention this
>feature.
Or perhaps it should be avoided altogether!
Consider the following,
Integrate[1/(x - 2I), {x, -1, 1, 1 + 3I, -1 + 3I, -1}] // FullSimplify
this gives the result I Pi (wrong by a factor 2)
And upon changing the contour (still closed and around the singularity)
Integrate[
1/(x - 2I), {x, -1 - I, 1 - I, 1 + 3I, -1 + 3I, -1 - I}] // FullSimplify
the result is 0.
Not the sort of results to inspire confidence in Mathematica's integration
methods!
(NIntegrate does give the correct result for both contours however)
Cheers,
Bill
I wonder if the problem isn't so much with the way Integrate
handles the form
Integrate[f[x],{x,x0,x1,x2, ...}]
but Integrate may incorrectly do the integral along one of the line
segments. Consider the problem below (using Version 4).
In[1]:=
Integrate[1/(x - 2I), {x, -1 + 3I, 1 + 3I}] // N
Out[1]=
0. + 1.5708*I
In[2]:=
NIntegrate[1/(x - 2I), {x, -1 + 3I, 1 + 3I}]
Out[2]=
0. - 1.5708*I
I am far from an expert on this subject, but I suspect NIntegrate got it
right and Integrate got it wrong. It seems with Version 4 we seldom hear
about errors with Integrate except when the integrand explicitly involves
complex numbers, or the limits of integration are complex. In any case I
think one should always verify results from Integrate with NIntegrate.