Re: Piecewise functions
- To: mathgroup at smc.vnet.net
- Subject: [mg51587] Re: Piecewise functions
- From: Bill Rowe <readnewsciv at earthlink.net>
- Date: Sat, 23 Oct 2004 00:23:10 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
On 10/21/04 at 10:22 PM, luca at nospam.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.
Yes, it is possible to do this. For example you could do
y[x_] := x /; x > 3
y[x_] := -x /; -1 < x < 3
y[x_] := 1 /; x < -1
and
Plot[y[x], {x, -2, 5}];
verifies the function y behaves as desired. But there are advantages to using Unit step
For example, trying to integrate y
Integrate[y[x], {x, -2, 0}]
Integrate[y[x], {x, -2, 0}]
simply returns the integral unevaluated.
Using Unit step
g[x_] := UnitStep[-x - 1] - x*(UnitStep[x + 1] - UnitStep[x - 3]) +
x*UnitStep[x - 3]
and then
Plot[g[x], {x, -2, 5}];
show g is the same function as y
now
Integrate[g[x], {x, -2, 0}]
3/2
works since Mathematica knows how to deal with the UnitStep function. Note g could have been written as
g[x_]:=UnitStep[-x - 1] + 2*x*UnitStep[x - 3] - x*UnitStep[x + 1]
which is somewhat simpler than what I wrote above. But the way I wrote it above is easier for me to see what g does.
--
To reply via email subtract one hundred and four