Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #10480
| From | Bill Rowe <readnews@sbcglobal.net> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Bug in NIntegrate[]? |
| Date | 2012-06-15 19:31 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <jrg2i2$sjb$1@smc.vnet.net> (permalink) |
On 6/15/12 at 3:41 AM, vokaputs@gmail.com (GS) wrote:
>I define the function f[x] as follows:
>f[x_] := 0 /; x < 0 || x > 1; f[x_] := 1
>It is zero outside of the interval [0,1]. This can be verified by
>plotting Plot[f[x], {x, -1, 2}]
>Now I integrate it from -1 to 2: In[270]:= NIntegrate[f[x], {x, -1,
>2}] Out[270]= 3.
>The result should be 1, but it is 3. Clearly Mathematica ignores the
>fact that f[x] is zero outside of [0,1].
>This caused a lot of headache for me recently when I encountered
>such behavior in one of my research code. GS
This does appear to be a bug. Instead of using logical operators
to define your function why not define it in terms of
HeavisideTheta, i.e.
g[x_] := HeavisideTheta[x] - HeavisideTheta[x - 1]
The advantage of this approach is Mathematica know how to
integrate and differentiate HeavisideTheta. That is:
In[6]:= Integrate[g[x], {x, -2, 1}]
Out[6]= 1
Note, NIntegrate does have problems with this definition. That is
In[7]:= NIntegrate[g[x], {x, -2, 1}]
Out[7]= 1.00024
with a warning about failure to converge with 9 recursive bisections
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re: Bug in NIntegrate[]? Bill Rowe <readnews@sbcglobal.net> - 2012-06-15 19:31 +0000
csiph-web