Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'Piecewise' topicStudent Support Forum > General > "Piecewise"

< Previous CommentHelp | Reply To Comment | Reply To Topic
Author Comment/Response
Henry Lamb
10/14/02 11:10pm

Here are two ways to do it.

First, you can use the Which function.

f[x_] := Which[x < 0, 0, x < 1, 1, x < 2, -1, True, 0]

Or you can do the same thing with the UnitStep function.

f[x_] := UnitStep[x] - 2 UnitStep[x - 1] + UnitStep[x - 2]

URL: ,

Subject (listing for 'Piecewise')
Author Date Posted
Piecewise Chad 10/12/02 10:49am
Re: Piecewise Tim Cooper 10/14/02 10:57am
Re: Piecewise Henry Lamb 10/14/02 11:10pm
< Previous CommentHelp | Reply To Comment | Reply To Topic