Integrate ???

*To*: "mathgroup" <mathgroup at yoda.ncsa.uiuc.edu>*Subject*: Integrate ???*From*: "WILLIAM M. GOLDING" <golding at ccf1.nrl.navy.mil>*Date*: 7 Nov 90 21:48:00 EDT

Hi there, Sorry, to keep bringing up this integrate point but its been nagging at me. I agree with everyone that mathematica is doing the definite integral by doing the indefinite integral and evaluating at 0 and 2 Pi. The problem is that it's doing the indefinite integral incorrectly. It's not totally incorrect, the integral is legit for the range 0 to Pi but negative of the right answer for the range Pi to 2 Pi. I don't know how important this is in the whole scheme of things but it sure makes me aware that one has to take with a few grains of salt the results obtained from a symbolics package. Obviously the integral could be done over the two ranges separately and pieced together, but when the program comes back and tells you its got the answer I want to be able to believe it. Anyways here is the original problem an how I think it should be solved. Integrate[Sqrt[2-2 Cos[x]],{x,0,2 Pi}] simplify the integrand 2-2 Cos[x] = 2 - Exp[I x] - Exp[-I x] = - [ Exp[I x/2]- Exp[-I x/2] ]^2 = - 4 I^2 Sin[x/2]^2 = 4 Sin[x/2]^2 We want the square root of this last expression so we get Sqrt[ 2-2 Cos[x] ] = Sqrt[ 4 Sin[x/2]^2 ] = Abs [ 2 Sin[x/2] ] In general, we have to include the absolute value sign here because we might not know the range of the integration variable. That is assuming x to be real, and there is no reason in this case not to assume x to be real, we have taken the positve sqrt of number which is definitely >= 0, and we require the result to be on the positive branch of our square root function. For example, suppose x = 3 Pi then if we exclude the absolute value sign we get Sqrt[ 4 Sin[3 Pi/2]^2] = 2 Sin[3 Pi/2] = 2 (-1) = - 2 but the Sqrt function must be >= 0 if we're going to stay on the positive branch, so the absolute value sign is necessary in the general case. Actually, with the integrand in this form and limiting x to the range 0 to 2 Pi as for our special case the Abs is not needed since 2 Sin[x/2] = 2 Abs[ Sin[x/2] ] 0 <= x <= 2 Pi . Thus we should be able to calculate the indefinte integral from Integrate[ Sqrt[2-2 Cos[x]] ,x] = Integral[ 2 Sin[x/2] ,x] = -4 Cos[x/2] only for 0<= x <= 2 Pi . To find the definite integral as in the original problem we get Integrate[Sqrt[2-2 Cos[x]],{x,0,2 Pi}] = | 2 Pi = ( -4 Cos[x/2] )| | 0 = -4 ( Cos[Pi] - Cos[0] ) = -4 ( -1 - 1 ) = 8 And this is the correct result at last. The result that Mathematica gives for the indefinite integral is In[1]:= Integrate [Sqrt[ 2-2 Cos[x]] , x ] -4 Out[1]= ----------------------- 2 Sin[x] Sqrt[1 + -------------] 2 (1 + Cos[x]) By using a little algebra and trigonometry you can show that this last result is the same as ours in the range 0 to Pi , and the negative of ours in the range pi to 2 Pi . That is The indefinite integral that mathematica produces is equivalent to -4 Cos[x/2] 0 <= x <= Pi (Identical to our result except our range is 0 to 2 Pi) 4 Cos[x/2] Pi <= x <= 2 Pi So we evaluate this at 0 and get -4 then we evaluate at 2 Pi and get -4 take the difference and the result is zero which is what mathematica has been getting. Notice that this function is continuous at x=Pi, but has discontinuous slope at x = Pi. Is it unreasonable for the integral of a continuous function to have discontinuous slope within the integration range. And if so might this be used as a clue to expect an error in the integration algorithm. The thing that bothers me about all this is that it is possible to get an integral that covers the whole integration range and seems reasonable, without mathematica once mentioning that there might be a problem with what we are doing. Here is an example of the neglect of the range applicability that I thought interesting. In[2]:= Sqrt[Sin[x]^2] Out[2]= Sin[x] Seems like a reasonable result but what about In[3]:= Integrate[Sqrt[Sin[x]^2] , x ] Out[3]= -Cos[x] In[4]:= Quit In[1]:= Sqrt[Sin[x]^2] Out[1]= Sin[x] Seems like a reasonable result but what about x = 3 Pi/2 In[2]:= Integrate[Sqrt[Sin[x]^2] , x] Out[2]= -Cos[x] It decided that Sin[x] was what I really wanted to integrate In[3]:= Integrate[Sqrt[Sin[x]^2],{x,0,Pi}] Out[3]= 2 This is right !!! In[4]:= Integrate[Sqrt[Sin[x]^2],{x,Pi,2 Pi}] Out[4]= -2 This is wrong !! In[5]:= Integrate[Sqrt[Sin[x]^2],{x,0,2 Pi}] Out[5]= 0 This is wrong ! In[6]:= I Quit