Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2012

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Bug in NIntegrate[]?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg126898] Re: Bug in NIntegrate[]?
  • From: Tomas Garza <tgarza10 at msn.com>
  • Date: Fri, 15 Jun 2012 15:31:35 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <201206150741.DAA24405@smc.vnet.net>

A quick and ready answer: use Piecewise.
In[1]:= NIntegrate[Piecewise[{{1,0<x<=1}}],{x,-2,1}]Out[1]= 1.
-Tomas

> Date: Fri, 15 Jun 2012 03:41:03 -0400
> From: vokaputs at gmail.com
> Subject: Bug in NIntegrate[]?
> To: mathgroup at smc.vnet.net
>
> 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
>



  • Prev by Date: Re: Can't work with Mathematica 8
  • Next by Date: Re: Bug in NIntegrate[]?
  • Previous by thread: Re: Bug in NIntegrate[]?
  • Next by thread: Re: Bug in NIntegrate[]?