MathGroup Archive 1999

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

Search the Archive

Continuous Integrals for Piecewise Continuous Functions

  • To: mathgroup at
  • Subject: [mg17267] Continuous Integrals for Piecewise Continuous Functions
  • From: Jack Goldberg <jackgold at>
  • Date: Fri, 30 Apr 1999 02:34:47 -0400
  • Sender: owner-wri-mathgroup at

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[1]: MakePC[G:{_,{x_,_,_}}..] := 

	Apply[Plus, List[G] /.

( 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[2]:=  SquareWave[x_] := MakePC[{1,{x,0,1}]
Out[2]= -1/2 Sign[-1+x]+Sign[x]/2

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

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

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

(Sign handles Infinities well).

Now the integration.

In[5]:= Unprotect[Integrate];

In[6]:= Integrate[f_.*Sign[x_+a_.],x_] := 

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

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

In[8]:= Protect[Integrate]

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

Some final comments:
	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

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