       Re: Integration of piecewise function

• To: mathgroup at smc.vnet.net
• Subject: [mg52485] Re: [mg52463] Integration of piecewise function
• From: Bob Hanlon <hanlonr at cox.net>
• Date: Mon, 29 Nov 2004 01:22:32 -0500 (EST)
• Sender: owner-wri-mathgroup at wolfram.com

```Define the function with UnitStep

Clear[X,w,c];

X[w_] := UnitStep[w]-2UnitStep[w-2]+UnitStep[w-4];

Plot[X[w],{w,-1,5}, PlotStyle->RGBColor[1, 0, 0]];

At the discontinuities, the limit is from the right

X /@ {0,2,4}

{1,-1,0}

Plot[Evaluate[Integrate[X[t], {t,-Infinity,w}]],{w,-1,5},
PlotStyle->RGBColor[1, 0, 0]];

Integrate[X[w],{w,-Infinity,Infinity}]

0

More generally, for the integral from w1 to w2 with w1<=w2

int = Integrate[X[w],{w,-Infinity,w2}]-
Integrate[X[w],{w,-Infinity,w1}]

(-(w1 - 4))*UnitStep[w1 - 4] + 2*(w1 - 2)*UnitStep[w1 - 2] - w1*UnitStep[w1]
+ (w2 - 4)*UnitStep[w2 - 4] -
2*(w2 - 2)*UnitStep[w2 - 2] + w2*UnitStep[w2]

Note that the integral is evaluated as the difference of two integrals.  This
avoids problems in evaluating the results at the discontinuities such as

Integrate[X[w],{w,w1,w2}]/.
{{w1->0, w2->8},{w1->2, w2->8},{w1->4, w2->8}}

{8,-14,4}

The actual values are

int /. {{w1->0, w2->8},{w1->2, w2->8},{w1->4, w2->8}}

{0,-2,0}

Cases for different ranges of w1 and w2 (w1 <= w2) can be evaluated using
Simplify

c[w_] := (#[]<=w<#[])& /@
Partition[{-Infinity,0,2,4,Infinity},2,1];

cond = And@@#&/@Simplify[
Select[
Flatten[
Outer[List,c[w1],c[w2]],1],
#[[1,1]]<=#[[2,1]]&],
Element[{w1,w2}, Reals]];

Simplify[Table[
{Simplify[int,cond[[n]]],cond[[n]]},
{n,Length[cond]}] //.
{s___,{0, c1_}, m___,{0,c2_},f___}:>
{s,{0,c1||c2},m,f}]

{{0, (w2 >= 4 && (w1 >= 4 || w1 < 0)) || (w1 < 0 && w2 < 0)},
{w2, w1 < 0 && Inequality[0, LessEqual, w2, Less, 2]},
{4 - w2, w1 < 0 && Inequality[2, LessEqual, w2, Less, 4]},
{w2 - w1, Inequality[0, LessEqual, w1, Less, 2] && Inequality[0, LessEqual,
w2, Less, 2]},
{-w1 - w2 + 4, Inequality[0, LessEqual, w1, Less, 2] && Inequality[2,
LessEqual, w2, Less, 4]},
{-w1, Inequality[0, LessEqual, w1, Less, 2] && w2 >= 4},
{w1 - w2, Inequality[2, LessEqual, w1, Less, 4] && Inequality[2, LessEqual,
w2, Less, 4]},
{w1 - 4, Inequality[2, LessEqual, w1, Less, 4] && w2 >= 4}}

Similar results are available much more directly in version 5.1 using
PiecewiseExpand

Simplify[PiecewiseExpand[int], w1<=w2]

Piecewise[{{w1 - 4, Inequality[2, LessEqual, w1, Less, 4] && w2 >= 4},
{-w1, Inequality[0, LessEqual, w1, Less, 2] && w2 >= 4},
{4 - w2, w1 < 0 && Inequality[2, LessEqual, w2, Less, 4]},
{-w1 - w2 + 4, Inequality[0, LessEqual, w1, Less, 2] && Inequality[2,
LessEqual, w2, Less, 4]},
{w1 - w2, Inequality[2, LessEqual, w1, Less, 4] && Inequality[2, LessEqual,
w2, Less, 4]},
{w2, w1 < 0 && Inequality[0, LessEqual, w2, Less, 2]},
{w2 - w1, Inequality[0, LessEqual, w1, Less, 2] && Inequality[0, LessEqual,
w2, Less, 2]}}]

However, note that one case is missing when using PiecewiseExpand.

Bob Hanlon

>
> From: Riccardo <ricky at nospam.it>
To: mathgroup at smc.vnet.net
> Date: 2004/11/28 Sun AM 01:06:46 EST
> To: mathgroup at smc.vnet.net
> Subject: [mg52485] [mg52463] Integration of piecewise function
>
> <inviati & spediti>
>
> I just defined a function like this:
>
> X[\[Omega]_] := 0 /; \[Omega] < 0;
> X[\[Omega]_] := 1 /; 0 < \[Omega] < 2;
> X[\[Omega]_] := -1 /; 2 < \[Omega] < 4;
> X[\[Omega]_] := 0 /; \[Omega] > 4;
>
> Is it possible now to integrate it from -infinity to +infinity? I've
> already tried and it doesn't give me the result.
> Thanks.
>
> Luca
>
>

```

• Prev by Date: Re: []Speeding Up Indexing and Joining
• Next by Date: Re: a bug in many variables integration ?
• Previous by thread: Re: Integration of piecewise function
• Next by thread: Re: Integration of piecewise function