Re: Wrong Integral result for a Piecewise function
- To: mathgroup at smc.vnet.net
- Subject: [mg58614] Re: Wrong Integral result for a Piecewise function
- From: Maxim <ab_def at prontomail.com>
- Date: Sun, 10 Jul 2005 05:12:27 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
On Thu, 7 Jul 2005 09:42:42 +0000 (UTC), Andrzej Kozlowski
<akozlowski at gmail.com> wrote:
>
> If you try instead
>
>
> g[x_] = FullSimplify[Integrate[UnitStep[2y + 2z - (x - 1)]*UnitStep[x
> - 2y - 2z], {y, 0, 1}, {z, 0, 1}]]
>
> (this takes a while to complete) then
>
> Plot[g[x],{x,0,5}]
>
> looks correct. Also
>
> In[18]:=
> NIntegrate[g[x], {x, 0, 5}]
>
> Out[18]=
> 1.
>
> In[19]:=
> Integrate[g[x], {x, 0, 5}]
>
> Out[19]=
> 1
>
> This, of course, is the pre-Mathematica 5 way of doing these things
> which only goes to confirm that progress is not always improvement ;-)
>
> Andrzej Kozlowski
> Chiba, Japan
>
In version 5.1.0 this gives an answer which is correct everywhere except
at the integer points:
In[1]:=
g[x_] = Integrate[UnitStep[2*y + 2*z - x + 1]*UnitStep[x - 2*y - 2*z],
{y, 0, 1}, {z, 0, 1}]
Out[1]=
(1/8)*(2*(-1 + (-2 + x)*x)*UnitStep[1 - x] + 2*(-2 + x)^2*UnitStep[2 - x]
+ 2*(-2 + x)*x*UnitStep[2 - x] - 2*(7 + (-6 + x)*x)*UnitStep[3 - x] - (-5
+ x)*UnitStep[5 - x]*(6 - 2*x + (-1 + x)*UnitStep[-3 + x]) + UnitStep[4 -
x]*(-4*UnitStep[1 - x/2] + (-4 + x)*(4 - 2*x + x*UnitStep[-2 + x])) + (-3
+ x)*UnitStep[3 - x]*(2 - 2*x + (1 + x)*UnitStep[-1 + x]) - 2*(-2
+ x^2)*UnitStep[-x] - (-4 + x^2)*UnitStep[2 - x, x])
In[2]:=
Reduce[g[x] != If[x == 3, 3/8, 0] + If[0 < x < 1, x^2/8, 0] + If[1 <= x <=
2, (1/8)*(-1 + 2*x), 0] + If[2 < x < 3, (1/8)*(-9 + 10*x - 2*x^2), 0]
+ If[Inequality[3, Less, x, LessEqual, 4], (1/8)*(9 - 2*x), 0] + If[4 < x
< 5, (1/8)*(-5 + x)^2, 0]]
Out[2]=
x == 0 || x == 1 || x == 2 || x == 3
This is always a potential pitfall when the answer is returned as a sum of
UnitStep terms, e.g. as UnitStep[-x] + (x + 1)*UnitStep[x]. It is likely
that the value at x = 0 will be incorrect, because both terms are equal to
1 at zero, not just one of them. Thus Limit[g[x], x -> 0] is correct but
g[0] isn't.
Maxim Rytin
m.r at inbox.ru
- Follow-Ups:
- Re: Re: Wrong Integral result for a Piecewise function
- From: Andrzej Kozlowski <akozlowski@gmail.com>
- Re: Re: Wrong Integral result for a Piecewise function