Re: Piecewise functions
- To: mathgroup at smc.vnet.net
- Subject: [mg51607] Re: Piecewise functions
- From: "Dr. Wolfgang Hintze" <weh at snafu.de>
- Date: Wed, 27 Oct 2004 01:54:12 -0400 (EDT)
- References: <cl9tau$7oi$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Luca, 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 In[335]:= a = -2; b = 3; Clear[f] f[x_] := UnitStep[x - a]*UnitStep[b - x] Plot[f[x], {x, a - 1, b + 1}]; Clear[g] 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. Wolfgang 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 > >