Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

Re: Re: Wrong Integral result for a Piecewise function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg58618] Re: [mg58614] Re: Wrong Integral result for a Piecewise function
  • From: Andrzej Kozlowski <akozlowski at gmail.com>
  • Date: Sun, 10 Jul 2005 16:51:36 -0400 (EDT)
  • References: <200507100912.FAA06529@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On 10 Jul 2005, at 18:12, Maxim wrote:

> 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
>
>


This suggests a simple but rather curious remedy. First define gg as  
above:

gg[x_] = FullSimplify[Integrate[UnitStep[2y + 2z - (x - 1)]*UnitStep[x
- 2y - 2z], {y, 0, 1}, {z, 0, 1}]];

and then define g simply as:

g[x_] := Limit[gg[t], t -> x]

This now gives correct answers though the more explicit answer given  
by the other methods seems clearly preferable.

Andrzej Kozlowski

Chiba, Japan


  • Prev by Date: Re: Complement replacement
  • Next by Date: Planetarium.m
  • Previous by thread: Re: Wrong Integral result for a Piecewise function
  • Next by thread: Re: Re: Wrong Integral result for a Piecewise function