From: David W.Cantrell on
Andrzej Kozlowski <akoz(a)mimuw.edu.pl> wrote:
> On 4 Jun 2006, at 15:01, Chris Chiasson wrote:
>
> > The Integrate result seems pretty weak. Is there any way to obtain a
> > more explicit exact answer besides manually converting the Piecewise
> > function to two UnitStep functions? Can the same be done if the final
> > limit of integration is a variable?
> >
> > in
> >
> > load[x_]=-9*10^3*DiracDelta[x]+Piecewise[{{x*10*(10^3/3),
> > 0<=x<=3}}]-6*10^3*DiracDelta[x-5]//InputForm
> >
> > out
> >
> > -6000*DiracDelta[-5 + x] - 9000*DiracDelta[x] +
> > Piecewise[{{(10000*x)/3, 0 <= x <= 3}}, 0]
> >
> > in
> >
> > Integrate[load[x],{x,0,5}]//InputForm
> >
> > out
> >
> > Integrate[InputForm[-6000*DiracDelta[-5 + x] - 9000*DiracDelta[x] +
> > Piecewise[{{(10000*x)/3, 0 <= x <= 3}}, 0]], {x, 0, 5}]
> >
> > --
> > http://chris.chiasson.name/
> >
>
> I am sure Maxim does not need my help to advertise his package but
> somehow people still keep posting such questions with surprising
> frequency.

It shouldn't surprise you. Such questions will continue to be posted
frequently until Mathematica _itself_ can adequately handle integration of
Piecewise functions.

> Even if for some reason you do not want to use a third
> party package you can always look at the Mathematica code inside,
> which should answer questions such as these.
>
> load[x_] = -9*10^3*
> DiracDelta[x] + Piecewise[{{x*10*(10^3/3), 0 <=
> x <= 3}}] - 6*10^3*DiracDelta[x - 5];
> << piecewise`
>
> In[3]:=
> PiecewiseIntegrate[load[x],{x,0,5}]
>
> Out[3]=
> 0

That might or might not be what Chris wanted. It depends on whether he
wanted integration of DiracDelta to be handled as Mathematica does or as
PiecewiseIntegrate does.

Using Mathematica, we have, for example,

In[28]:= Integrate[DiracDelta[x],{x,0,2}]
Out[28]= 1/2

rather than 1, which I infer is what PiecewiseIntegrate would do.

If Chris really wanted the integration of the DiracDelta functions to be
handled as Mathematica does, then I should think he'd want
Integrate[load[x],{x,0,5}] to return 7500, rather than your Out[3]=0.

David

> In[4]:=
> PiecewiseIntegrate[load[x], {x, 0, a}]
>
> Out[4]=
> If[Inequality[0, Less, a, LessEqual, 3], (5000*a^2)/3, 0] + If[3 < a,
> 15000, 0] + If[a < 0, 9000, 0] + If[0 <= a, -9000, 0] +
> If[5 <= a, -6000, 0]
>
> Andrzej Kozlowski

From: Andrzej Kozlowski on

On 5 Jun 2006, at 23:26, David W. Cantrell wrote:

>
>
> Andrzej Kozlowski <akoz(a)mimuw.edu.pl> wrote:
>> On 4 Jun 2006, at 15:01, Chris Chiasson wrote:
>>
>>> The Integrate result seems pretty weak. Is there any way to obtain a
>>> more explicit exact answer besides manually converting the Piecewise
>>> function to two UnitStep functions? Can the same be done if the
>>> final
>>> limit of integration is a variable?
>>>
>>> in
>>>
>>> load[x_]=-9*10^3*DiracDelta[x]+Piecewise[{{x*10*(10^3/3),
>>> 0<=x<=3}}]-6*10^3*DiracDelta[x-5]//InputForm
>>>
>>> out
>>>
>>> -6000*DiracDelta[-5 + x] - 9000*DiracDelta[x] +
>>> Piecewise[{{(10000*x)/3, 0 <= x <= 3}}, 0]
>>>
>>> in
>>>
>>> Integrate[load[x],{x,0,5}]//InputForm
>>>
>>> out
>>>
>>> Integrate[InputForm[-6000*DiracDelta[-5 + x] - 9000*DiracDelta[x] +
>>> Piecewise[{{(10000*x)/3, 0 <= x <= 3}}, 0]], {x, 0, 5}]
>>>
>>> --
>>> http://chris.chiasson.name/
>>>
>>
>> I am sure Maxim does not need my help to advertise his package but
>> somehow people still keep posting such questions with surprising
>> frequency.
>
> It shouldn't surprise you. Such questions will continue to be posted
> frequently until Mathematica _itself_ can adequately handle
> integration of
> Piecewise functions.

No doubt you are right, but I was referring to the fact that I
mentioned the package in a related context only a few days earlier
and Maxim has posted several times in detail on this topic. So I
naturaly felt a little bit like a person trying to help another
person with a Sisyphean task.
>
>> Even if for some reason you do not want to use a third
>> party package you can always look at the Mathematica code inside,
>> which should answer questions such as these.
>>
>> load[x_] = -9*10^3*
>> DiracDelta[x] + Piecewise[{{x*10*(10^3/3), 0 <=
>> x <= 3}}] - 6*10^3*DiracDelta[x - 5];
>> << piecewise`
>>
>> In[3]:=
>> PiecewiseIntegrate[load[x],{x,0,5}]
>>
>> Out[3]=
>> 0
>
> That might or might not be what Chris wanted. It depends on whether he
> wanted integration of DiracDelta to be handled as Mathematica does
> or as
> PiecewiseIntegrate does.
>
> Using Mathematica, we have, for example,
>
> In[28]:= Integrate[DiracDelta[x],{x,0,2}]
> Out[28]= 1/2
>
> rather than 1, which I infer is what PiecewiseIntegrate would do.

I confess that I never noticed that Integrate and DiracDelta in
Mathematica behaved like this at end points. It seems to me that the
Piecewise approach, which assumes that boundary points are treated
the same as interior points, is the more natural. But Chris obviously
was not interested in the answer to this particular problem but in
more general matters. It is trivial to modify the behaviour of the
package in this respect (by adding ones own rules for handling
DiracDelta) to make it conform with what Mathematica does, if one
really wanted to. But my main point was that the package is
interesting in its own right and it seems to me that anyone seriously
interested in this topic would have already taken a look at it. Why,
even people not seriously interested in it, like myself, have done so
and found interesting and instructive things in it.

Andrzej

>
> If Chris really wanted the integration of the DiracDelta functions
> to be
> handled as Mathematica does, then I should think he'd want
> Integrate[load[x],{x,0,5}] to return 7500, rather than your Out[3]=0.
>
> David
>
>> In[4]:=
>> PiecewiseIntegrate[load[x], {x, 0, a}]
>>
>> Out[4]=
>> If[Inequality[0, Less, a, LessEqual, 3], (5000*a^2)/3, 0] + If[3 < a,
>> 15000, 0] + If[a < 0, 9000, 0] + If[0 <= a, -9000, 0] +
>> If[5 <= a, -6000, 0]
>>
>> Andrzej Kozlowski

From: Chris Chiasson on
Actually, even I have used the PiecewiseIntegrate package before.
Maxim mentioned it in answer to a problem I had with DSolve & a
Piecewise forcing function. I have also noticed the problem with
DiracDelta functions occurring at the end points of integration. This
makes me wonder how they are handled by DSolve and NDSolve. I am not
presently at a Mathematica capable computer, so I can't test it.

On 6/5/06, Andrzej Kozlowski <akoz(a)mimuw.edu.pl> wrote:
> *This message was transferred with a trial version of CommuniGate(tm) Pro*
>
> On 5 Jun 2006, at 23:26, David W. Cantrell wrote:
>
> >
> >
> > Andrzej Kozlowski <akoz(a)mimuw.edu.pl> wrote:
> >> On 4 Jun 2006, at 15:01, Chris Chiasson wrote:
> >>
> >>> The Integrate result seems pretty weak. Is there any way to obtain a
> >>> more explicit exact answer besides manually converting the Piecewise
> >>> function to two UnitStep functions? Can the same be done if the
> >>> final
> >>> limit of integration is a variable?
> >>>
> >>> in
> >>>
> >>> load[x_]=-9*10^3*DiracDelta[x]+Piecewise[{{x*10*(10^3/3),
> >>> 0<=x<=3}}]-6*10^3*DiracDelta[x-5]//InputForm
> >>>
> >>> out
> >>>
> >>> -6000*DiracDelta[-5 + x] - 9000*DiracDelta[x] +
> >>> Piecewise[{{(10000*x)/3, 0 <= x <= 3}}, 0]
> >>>
> >>> in
> >>>
> >>> Integrate[load[x],{x,0,5}]//InputForm
> >>>
> >>> out
> >>>
> >>> Integrate[InputForm[-6000*DiracDelta[-5 + x] - 9000*DiracDelta[x] +
> >>> Piecewise[{{(10000*x)/3, 0 <= x <= 3}}, 0]], {x, 0, 5}]
> >>>
> >>> --
> >>> http://chris.chiasson.name/
> >>>
> >>
> >> I am sure Maxim does not need my help to advertise his package but
> >> somehow people still keep posting such questions with surprising
> >> frequency.
> >
> > It shouldn't surprise you. Such questions will continue to be posted
> > frequently until Mathematica _itself_ can adequately handle
> > integration of
> > Piecewise functions.
>
> No doubt you are right, but I was referring to the fact that I
> mentioned the package in a related context only a few days earlier
> and Maxim has posted several times in detail on this topic. So I
> naturaly felt a little bit like a person trying to help another
> person with a Sisyphean task.
> >
> >> Even if for some reason you do not want to use a third
> >> party package you can always look at the Mathematica code inside,
> >> which should answer questions such as these.
> >>
> >> load[x_] = -9*10^3*
> >> DiracDelta[x] + Piecewise[{{x*10*(10^3/3), 0 <=
> >> x <= 3}}] - 6*10^3*DiracDelta[x - 5];
> >> << piecewise`
> >>
> >> In[3]:=
> >> PiecewiseIntegrate[load[x],{x,0,5}]
> >>
> >> Out[3]=
> >> 0
> >
> > That might or might not be what Chris wanted. It depends on whether he
> > wanted integration of DiracDelta to be handled as Mathematica does
> > or as
> > PiecewiseIntegrate does.
> >
> > Using Mathematica, we have, for example,
> >
> > In[28]:= Integrate[DiracDelta[x],{x,0,2}]
> > Out[28]= 1/2
> >
> > rather than 1, which I infer is what PiecewiseIntegrate would do.
>
> I confess that I never noticed that Integrate and DiracDelta in
> Mathematica behaved like this at end points. It seems to me that the
> Piecewise approach, which assumes that boundary points are treated
> the same as interior points, is the more natural. But Chris obviously
> was not interested in the answer to this particular problem but in
> more general matters. It is trivial to modify the behaviour of the
> package in this respect (by adding ones own rules for handling
> DiracDelta) to make it conform with what Mathematica does, if one
> really wanted to. But my main point was that the package is
> interesting in its own right and it seems to me that anyone seriously
> interested in this topic would have already taken a look at it. Why,
> even people not seriously interested in it, like myself, have done so
> and found interesting and instructive things in it.
>
> Andrzej
>
> >
> > If Chris really wanted the integration of the DiracDelta functions
> > to be
> > handled as Mathematica does, then I should think he'd want
> > Integrate[load[x],{x,0,5}] to return 7500, rather than your Out[3]=0.
> >
> > David
> >
> >> In[4]:=
> >> PiecewiseIntegrate[load[x], {x, 0, a}]
> >>
> >> Out[4]=
> >> If[Inequality[0, Less, a, LessEqual, 3], (5000*a^2)/3, 0] + If[3 < a,
> >> 15000, 0] + If[a < 0, 9000, 0] + If[0 <= a, -9000, 0] +
> >> If[5 <= a, -6000, 0]
> >>
> >> Andrzej Kozlowski
>
>


--
http://chris.chiasson.name/

From: Chris Chiasson on
> I confess that I never noticed that Integrate and DiracDelta in
> Mathematica behaved like this at end points. It seems to me that the
> Piecewise approach, which assumes that boundary points are treated
> the same as interior points, is the more natural. But Chris obviously
> was not interested in the answer to this particular problem but in
> more general matters. It is trivial to modify the behaviour of the
> package in this respect (by adding ones own rules for handling
> DiracDelta) to make it conform with what Mathematica does, if one
> really wanted to. But my main point was that the package is
> interesting in its own right and it seems to me that anyone seriously
> interested in this topic would have already taken a look at it. Why,
> even people not seriously interested in it, like myself, have done so
> and found interesting and instructive things in it.
>
> Andrzej

I think Mathematica's Integrate does this to preserve the identity:
Integrate[f[x],{x,a,c}]==Integrate[f[x],{x,a,b}]+Integrate[f[x],{x,b,c}]

There is a danger of violating this when using PiecewiseIntegrate:

In[1]:=
<<PiecewiseIntegrate.m
load[x_]=-9*10^3*DiracDelta[x]-
Piecewise[{{x*10*(10^3/3),0\[LessEqual]x\[LessEqual]3}}]-6*10^3*
DiracDelta[x-5]
Integrate[load[x],{x,-10,10}]
PiecewiseIntegrate[load[x],{x,-10,10}]
{PiecewiseIntegrate[load[x],{x,-10,0}],PiecewiseIntegrate[load[x],{x,0,5}],
PiecewiseIntegrate[load[x],{x,5,10}]}
Plus@@%
Out[2]=
-6000*DiracDelta[-5 + x] - 9000*DiracDelta[x] -
Piecewise[{{(10000*x)/3, 0 <= x <= 3}}]
Out[3]=
-30000
Out[4]=
-30000
Out[5]=
{-9000,-30000,-6000}
Out[6]=
-45000
--
http://chris.chiasson.name/

From: Andrzej Kozlowski on

On 8 Jun 2006, at 07:02, Chris Chiasson wrote:

>> I confess that I never noticed that Integrate and DiracDelta in
>> Mathematica behaved like this at end points. It seems to me that the
>> Piecewise approach, which assumes that boundary points are treated
>> the same as interior points, is the more natural. But Chris obviously
>> was not interested in the answer to this particular problem but in
>> more general matters. It is trivial to modify the behaviour of the
>> package in this respect (by adding ones own rules for handling
>> DiracDelta) to make it conform with what Mathematica does, if one
>> really wanted to. But my main point was that the package is
>> interesting in its own right and it seems to me that anyone seriously
>> interested in this topic would have already taken a look at it. Why,
>> even people not seriously interested in it, like myself, have done so
>> and found interesting and instructive things in it.
>>
>> Andrzej
>
> I think Mathematica's Integrate does this to preserve the identity:
> Integrate[f[x],{x,a,c}]==Integrate[f[x],{x,a,b}]+Integrate[f[x],
> {x,b,c}]
>
> There is a danger of violating this when using PiecewiseIntegrate:
>
> In[1]:=
> <<PiecewiseIntegrate.m
> load[x_]=-9*10^3*DiracDelta[x]-
> Piecewise[{{x*10*(10^3/3),0\[LessEqual]x\[LessEqual]3}}]-6*10^3*
> DiracDelta[x-5]
> Integrate[load[x],{x,-10,10}]
> PiecewiseIntegrate[load[x],{x,-10,10}]
> {PiecewiseIntegrate[load[x],{x,-10,0}],PiecewiseIntegrate[load[x],
> {x,0,5}],
> PiecewiseIntegrate[load[x],{x,5,10}]}
> Plus@@%
> Out[2]=
> -6000*DiracDelta[-5 + x] - 9000*DiracDelta[x] -
> Piecewise[{{(10000*x)/3, 0 <= x <= 3}}]
> Out[3]=
> -30000
> Out[4]=
> -30000
> Out[5]=
> {-9000,-30000,-6000}
> Out[6]=
> -45000
> --
> http://chris.chiasson.name/

Chris

I realised this. However, I do not consider this identity correct in
this context. Mathematica often treats generalised functions as if
they were ordinary functions and this often lead to contradictions,
or at least unpleasant behaviour. Even if we for the time being
ignore the mathematical meaning of distributions you can get
inconsistent results such as this:


{Integrate[DiracDelta[x], {x, -1, 0}],
Integrate[DiracDelta[x], {x, -1, t}] /. t -> 0}


{1/2, 1}

Compare this with:

<<Piecewise`


{PiecewiseIntegrate[DiracDelta[x], {x, -1, 0}],
PiecewiseIntegrate[DiracDelta[x], {x, -1, t}] /. t -> 0}


{1,1}

Or looking at it form another angle:


Limit[PiecewiseIntegrate[DiracDelta[x], {x, -1, t}],
t -> 0, Direction -> 1]

0


Limit[PiecewiseIntegrate[DiracDelta[x], {x, -1, t}],
t -> 0, Direction -> -1]

1

So the Integral returned by Mathematica is not continuous either form
the left or from the right. The integral returned by
Piecewiseintegrate is continuous from the right, which is what is the
usual assumption in mathematical texts. But there is something even
worse about he Mathematica implementation.

In fact, if you write out the formula for the sum of integrals using
limits you will see that it holds for PiecwiseIntegrate too.
In fact, generalised functions are not "functions" (they have no
values at points) but are usually defined as functionals on a certain
space of functions on real line (there is also another approach in
terms of non-standard analysis, but that is not implemented in
Mathematica). These functionals are defined in terms of integrals
over the entire real line so formally you cannot integrate the
DiracDelta over a finite interval; you can only integrate it from -
Infinity to +Infinity, because that is how the functional is defined.
Integrals over finite intervals can then be defined as integrals over
the whole real line of products of DiracDelta and the characteristic
functions of these intervals. But look what happens when you use
Mathematica:


{Integrate[DiracDelta[x]*Boole[0 <= x <= 2],
{x, -Infinity, Infinity}], Integrate[DiracDelta[x],
{x, 0, 2}]}


{1, 1/2}


But these ought to be the same by definition! Again compare this with
PiecewiseIntegrate


{PiecewiseIntegrate[DiracDelta[x]*Boole[0 <= x <= 2],
{x, -Infinity, Infinity}], PiecewiseIntegrate[DiracDelta[x],
{x, 0, 2}]}


{1,1}


From the mathematical point of view I have no doubt here: Maxim got
it right and Mathematica got it wrong. Of course one can always say
that these are only different conventions and as is usual with
various conventions, once you understand them and get used to them
you usually find that you can use them equally successfully. Still,
there are just too many departures form standard mathematics for me
to be comfortable with the way Mathematica behaves in the above
examples.

Andrzej Kozlowski