Re: Bug in Integrate?
- To: mathgroup at yoda.ncsa.uiuc.edu
- Subject: Re: Bug in Integrate?
- From: uunet!decide!bobk (Bob Korsan)
- Date: Wed, 15 Aug 90 10:32:05 PDT
You write
----- Begin Included Message -----
>From saxony!uunet!yoda.ncsa.uiuc.edu!mathgroup-adm Tue Aug 14 20:59:55 1990
From: uunet!mathnx.byu.edu!smithw (William V. Smith)
To: mathgroup at yoda.ncsa.uiuc.edu
Subject: Bug in Integrate?
This problem came up in some instructional materials being developed
here. If any of you know what's going on here let me know. I told
the person who handed it to me, that it might be related to the rather
awkward way Mathematica handles square roots. So, try doing
this integration problem:
In[1]:=
a Integrate[Sqrt[(1-Cos[theta])^2+Sin[theta]^2],{theta,0,2 Pi}]
Out[1]:=
0
(*this is incorrect*)
In[2]:=
a NIntegrate[Sqrt[(1-Cos[theta])^2+Sin[theta]^2],{theta,0,2 Pi}]
Out[2]:=
8. a
(*this is correct*)
Date: Fri, 10 Aug 90 23:24:01 MDT
From: smithw at mathnx.byu.edu (William V. Smith)
To: mathgroup at yoda.ncsa.uiuc.edu
Subject: Re: Another mathematica bug?
Whoops! I just got a chance to look at this one again and it appears
that NEITHER Integrate nor NIntegrate give the correct answer. I
get 4aSqrt[2] working it out by hand. Sorry about that. Its been
a busy day. Somebody want to check this?
----- End Included Message -----
Well, you are correct, the trouble is with Sqrt. If you look at the
integrand and simplify
In[1]:=Simplify[Sqrt[(1-Cos[t])^2+Sin[t]^2]/.Sin[t]^2->1-Cos[t]^2]
Out[1]:=Sqrt[2 - 2 Cos[t]]
and then
In[2]:=Integrate[Sqrt[1-Cos[t]],t]
Out[2]:=
-2 Sqrt[2]
-----------------------
2
Sin[t]
Sqrt[1 + -------------]
2
(1 + Cos[t])
If you plot this you will notice that since Mathematica
always (EVEN WHEN IT SHOULDN'T) takes the positive
square root, the result is always negative in the
interval [0,2Pi]. Thus, the integrand evaluated at
both end points is the same and subtracts to zero.
This is a MAJOR BUG in version 1.2.1 and should be
corrected immediately.
Peace/Bob
===============================================================================
| "The range of what we think and do | Bob Korsan |
| is limited by what we fail to notice. | Decisions, Decisions! |
| And because we fail to notice that we | 2136 Lyon Avenue |
| fail to notice there is little we can | Belmont, CA 94002-1639 |
| do to change until we notice how | 1(415) 595-1206 |
| failing to notice shapes our thoughts | bobk at decide.UUCP |
| and deeds." | korsan at pa.reuter.com |
| -- R. D. Laing | {sun,uunet}!saxony!decide!bobk |
===============================================================================