From: Chris Chiasson on
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/

From: Bob Hanlon on
load[x_]=-9*10^3*
DiracDelta[x]+Piecewise[{{x*10*(10^3/3),0?x?3}},0]-6*10^3*DiracDelta[x-5];

If a bound of the integration is on a DiracDelta then Mathematica integrates that DiracDelta to 1/2 of its coefficient

Integrate[DiracDelta[x],{x,0,1}]

1/2

Integrate[DiracDelta[x],{x,-1,0}]

1/2

Integrate[DiracDelta[x],{x,-1,1}]

1

This impacts both ends of your integral

Integrate[#,{x,0,5}]&/@load[x]

7500

Integrate[#,{x,0,6}]&/@load[x]

4500

Integrate[#,{x,-1,5}]&/@load[x]

3000

Integrate[#,{x,-1,6}]&/@load[x]

0


Bob Hanlon

---- Chris Chiasson <chris(a)chiasson.name> 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/
>

--

Bob Hanlon
hanlonr(a)cox.net


From: Jean-Marc Gulliet on
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}]
>
Hi Chris,

You could try Maxim Rytin's PiecewiseIntegrate function [1].

From MathSource: "The notebook contains the implementation of four
functions PiecewiseIntegrate, PiecewiseSum, NPiecewiseIntegrate,
NPiecewiseSum. They are intended for working with piecewise continuous
functions, and also generalized functions in the case of
PiecewiseIntegrate. They support all the standard Mathematica piecewise
functions such as UnitStep, Abs, Max, as well as Floor and other
arithmetic piecewise functions. PiecewiseIntegrate supports the
multidimensional DiracDelta function and its derivatives. The arguments
of the piecewise functions can be non-algebraic and contain symbolic
parameters."

In[1]:=
load[x_] := -6000*DiracDelta[-5 + x] -
9000*DiracDelta[x] + Piecewise[
{{(10000*x)/3, 0 <= x <= 3}}, 0]

In[2]:=
Integrate[load[x], {x, 0, 5}]

Out[2]=
Integrate[-6000*DiracDelta[-5 + x] -
9000*DiracDelta[x] + Piecewise[
{{(10000*x)/3, 0 <= x <= 3}}], {x, 0, 5}]

In[103]:=
PiecewiseIntegrate[load[x], {x, 0, 5}]

Out[103]=
0

HTH,
Jean-Marc

[1]: Rytin, Maxim, _Integration of Piecewise Functions with
Applications_, Mathematica Package,
http://library.wolfram.com/infocenter/MathSource/5117/

From: Andrzej Kozlowski on

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

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: David W.Cantrell on
"Chris Chiasson" <chris(a)chiasson.name> 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?

I'm not sure. That's _essentially_ (but not literally) what I'd do.

> Can the same be done if the final limit of integration is a variable?

Yes.

Are you aware that (at least in version 5.1) using variable limits of
integration over UnitStep can reveal a bug? For example:

In[6]:= Integrate[UnitStep[x],{x,0,3}]
Out[6]= 3

In[7]:= Assuming[a<=b,Integrate[UnitStep[x],{x,a,b}]]
Out[7]= (b UnitStep[-a]+(-a+b) UnitStep[a]) UnitStep[b]

In[8]:= %/.{a->0,b->3}
Out[8]= 6

Out[8] doesn't agree with Out[6], which was correct. This discrepancy is
caused by Out[7] not being correct in general (even when a<=b).

Here's a possible remedy. We define our own unit step:

In[9]:= ourUnitStep[x_]:= (Abs[x]/x + 1)/2

In[10]:= Assuming[a<=b,Integrate[ourUnitStep[x],{x,a,b}]]
Out[10]= Piecewise[{{-a, a > 0 && b < 0 && a - b >= 0}, {b, b > 0 && a <
0}, {-2*a + b, a > 0 && b < 0 && a - b < 0}, {-a + b, (a == 0 && a - b < 0)
|| (a >= 0 && b >= 0 && a - b < 0)}}]

Messy, but AFAIK, correct whenever a <= b.

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

Neglecting the DiracDelta terms,

In[14]:= Assuming[a<=b,
Simplify[Integrate[(x*10*(10^3/3))(ourUnitStep[x]-ourUnitStep[x-3]),{x,a,
b}]]]

Out[14]= Piecewise[{{15000, b > 3 && a < 0}, {(-(5000/3))*(-9 + a^2), 0 <=
a < 3 && b > 3}, {(5000*b^2)/3, a < 0 && 0 < b <= 3}, {(-(5000/3))*(a^2 -
b^2), a < b && b <= 3 && (a == 0 || (a < 3 && 0 <= a && 0 <= b))}}]

The contributions from the DiracDelta terms can then be added to that.
(For some reason, I was unable to get the integral to evaluate if the
DiracDelta terms were present.)

David