       Continuous Integrals for Piecewise Continuous Functions

• To: mathgroup at smc.vnet.net
• Subject: [mg17267] Continuous Integrals for Piecewise Continuous Functions
• From: Jack Goldberg <jackgold at math.lsa.umich.edu>
• Date: Fri, 30 Apr 1999 02:34:47 -0400
• Sender: owner-wri-mathgroup at wolfram.com

```Hi Group,

After trying many different variants, I have finally settled
on a scheme that provides a simple answer to the question of
integrating piecewise continuous functions (abbreviated PC from
now on :-).

The key idea is this:  The rhs of the formula,

Integrate[f_.*Sign[x_-a_.].x_] = Integrate[f,{x,a,x}]*Sign[x-a]

is continuous for all x and its derivative exists and is  f*Sign[x-a]
at all x except possibly at x=a.  Since

f/2*(Sign[x-a] - Sign[x-b])

is the PC function which vanishes outside of [a,b] and is f in (a,b),
sums of this type can be used to construct any PC function and the
integration formula then provides the required continuous anti-derivative.
(Sums of continuous functions are continuous).
Here is the code without bells and whistles.

In: MakePC[G:{_,{x_,_,_}}..] :=

Apply[Plus, List[G] /.
({f_,{x,{a_,b_}}->f/2*Sign[x-a]-f/2*Sign[x-b])

( A typical argument of MakePC is  {expr,{x,a,b}} which is meant to
denote a function expr in (a,b), zero outside of [a,b].  The code
can be understood easily enough.
What happens here is this:  The sequence named G becomes a list and
each entry in this list is converted into the appropriate difference
of Sign functions.  The "Apply" converts the list to a sum).

Some nice examples. Plotting helps.

In:=  SquareWave[x_] := MakePC[{1,{x,0,1}]
Out= -1/2 Sign[-1+x]+Sign[x]/2

In:=  Tent[x_] := MakePC[{1+x,{x,-1,0}},{1-x,{x,0,1}}]
Out=  -1/2(1-x) Sign[-1+x] +1/2(1-x)Sign[x]-1/2(1+x)Sign[x] +
1/2(1+x)Sign[1+x]

I have written code that will clean up the Out, but
I don't want to clutter this post but see summary below).

In:= f[x_] := MakePC[{-1,{x,-Infinity,0}},{1,{x,0,Infinity}}]
Out= Sign[x]

(Sign handles Infinities well).

Now the integration.

In:= Unprotect[Integrate];

In:= Integrate[f_.*Sign[x_+a_.],x_] :=
Integrate[f,{x,-a,x}*Sign[x+a]

(Note the -a in the rhs.  This is due to the argument  x+a of Sign.)

In:= Integrate[h_+f_.*g_Sign,x_] := Integrate[h,x]+Integrate[f*g,x]

In:= Protect[Integrate]

Since the result of MakePC is a sum of the form  f*Sign[...], In
and the definition  In  should take care of all cases of MakePC
that are "well-formulated".

There are at least 6 extensions (improvements?) that can
be made to the code.  I have done them all and will send them to
anyone interested.
(1) If MakePC  has a single argument the outer {} are not necessary
and we could add this as a special case.
(2) An option to MakePC might be to plot the graph since I have found
it somewhat tedious trying to see if I really did get the right
function constructed.
(3) A list of rules (I called them SignRules) which enables us to
manipulate more complicated functions of Sign such as

Tent[x]^2*SquareWave[x]- Sign[x]

I can't think of any use for such a function; but since I knew
it was PC, I challanged myself to see if I could simplify it
by using a collection of rules.
(4) Clean up the output of MakePC
(5) Construct the code to handle definite integrals.
(6) Error catching steps.

I worked alone on this.  With no feedback to catch my often silly
programming errors, I would be very appreciative of any remarks.
My ego is not involved in this.  I just hope to stimulate both the
people at Mathematica (If I can do it, how come its not available?) and
those generous experts who have contributed so much to this group.

Jack Goldberg
Univ. of Mich
Math

```

• Prev by Date: looking for implementation of hash function
• Next by Date: Re: Counting list elements above/below a given value
• Previous by thread: CleanSlate and Version 3
• Next by thread: Arciving data in Oracle to comma delimited values???