MathGroup Archive 2004

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

Search the Archive

Re: Piecewise functions

  • To: mathgroup at
  • Subject: [mg51607] Re: Piecewise functions
  • From: "Dr. Wolfgang Hintze" <weh at>
  • Date: Wed, 27 Oct 2004 01:54:12 -0400 (EDT)
  • References: <cl9tau$7oi$>
  • Sender: owner-wri-mathgroup at


perhaps it helps in constructing your piecewise function if you use the 
following function which is unity in the interval [a,b] (assume a>b) and 
zero elsewhere

f[x_]:= UnitStep[x-a] * UnitStep[b-x]

This can also be written in linear form as

g[x_]:= UnitStep[x-a] - UnitStep[x-b]

Now you have each interval available for your definition.

If you like you can test it e.g. with
a = -2; b = 3;
f[x_] := UnitStep[x - a]*UnitStep[b - x]
Plot[f[x], {x, a - 1, b + 1}];
g[x_] := UnitStep[x - a] - UnitStep[x - b]
Plot[g[x], {x, a - 1, b + 1}];

Remark 1: the linear form (g) should be used as it facilitates the work 
for mathematica

Remark 2: I noticed (alas!) that Integrate does not work properly for 
piecewise functions (even is they have a continuous derivative) without 
UnitStep. Hence I strongly recommend using it.


Luca wrote:

> Hi all. I'm studying for the exam of signals and systems and I was
> trying to plot some kind of functions I transformed for exercise. So, I
> need to plot piecewise functions like:
> y(x) = x if x > 3
> y(x) = -x if -1 < x < 3
> y(x) = 1 else
> (should have been a system).
> I found out in the guide the chapter about this, and I learned that it
> is possible with the function UnitStep, which I know. Anyway, I found
> it difficult to determine the equation of the function using this
> method. Is it possible to do it simply writing everything like I did
> before, more or less? i.e. without having to determine the equation
> with the UnitStep function.
> Hope I've been clear enought. Many thanks.
> Luca

  • Prev by Date: Re: Re: Step by step answer ?
  • Next by Date: Re: f'[t]== x[t]+u[t] ?
  • Previous by thread: Re: Piecewise functions
  • Next by thread: Problems with typeset expression on SuSE Linux 9.1