Wolfram ResearchPRODUCTSPURCHASEFOR USERSCOMPANYOUR SITES
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.
Previous section-----Next section

3.2.3 Piecewise Functions

Boole[expr] give 1 if expr is True, and 0 if it is False

Turning conditions into numbers.

Boole[expr] is a basic function that turns True and False into 1 and 0. It is sometimes known as the characteristic function or indicator function.

This gives the area of a unit disk.

In[1]:=  Integrate[Boole[x^2 + y^2 LessEqual 1], {x, -1, 1}, {y, -1, 1}]

Out[1]=

Piecewise[{{ ,  }, { ,  }, ... }]
give the first  for which  is True
Piecewise[{{ ,  }, ... }, val] give val if all  are False

Piecewise functions.

It is often convenient to have functions with different forms in different regions. You can do this using Piecewise.

This plots a piecewise function.

In[2]:=  Plot[Piecewise[{{x^2, x < 0}, {1-x, x > 0}}], {x, -1, 1}]

Out[2]=

Piecewise functions appear in systems where there is discrete switching between different domains. They are also at the core of many computational methods, including splines and finite elements. Special cases include such functions as Abs, UnitStep, Clip, Sign, Floor and Max. Mathematica handles piecewise functions in both symbolic and numerical situations.


Any questions about topics on this page? Click here to get an individual response.Buy NowFree TrialMore Information



 © 2009 Wolfram Research, Inc.  Terms of Use  Privacy Policy |
Sign up for our newsletter: