Re: Piecewise functions
- To: mathgroup at smc.vnet.net
- Subject: [mg51573] Re: [mg51553] Piecewise functions
- From: Murray Eisenberg <murray at math.umass.edu>
- Date: Sat, 23 Oct 2004 00:22:03 -0400 (EDT)
- Organization: Mathematics & Statistics, Univ. of Mass./Amherst
- References: <200410220222.WAA07319@smc.vnet.net>
- Reply-to: murray at math.umass.edu
- Sender: owner-wri-mathgroup at wolfram.com
You CAN do it without UnitStep if you really want:
y[x_] := Which[x > 3, x, -1 < x < 3, -x, True, 1]
Plot[y[x], {x, -5, 5}];
But you'll get the same spurious vertical line segment at x = 3 that you
will if you do use UnitStep:
y[x_]:=x UnitStep[x - 3] - x(-UnitStep[x - 3] + UnitStep[x + 1]) +
(1 - UnitStep[x + 1]
Plot[y[x], {x, -5, 5}];
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.
--
Murray Eisenberg murray at math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower phone 413 549-1020 (H)
University of Massachusetts 413 545-2859 (W)
710 North Pleasant Street fax 413 545-1801
Amherst, MA 01003-9305
- References:
- Piecewise functions
- From: Luca <luca@nospam.it>
- Piecewise functions