Piecewise
Piecewise[{{val1,cond1},{val2,cond2},…}]
represents a piecewise function with values vali in the regions defined by the conditions condi.
Piecewise[{{val1,cond1},…},val]
uses default value val if none of the condi apply. The default for val is 0.
Details
- The condi are typically inequalities such as .
- The condi are evaluated in turn, until one of them is found to yield True.
- If all preceding condi yield False, then the vali corresponding to the first condi that yields True is returned as the value of the piecewise function.
- If any of the preceding condi do not literally yield False, the Piecewise function is returned in symbolic form.
- Only those vali explicitly included in the returned form are evaluated.
- Elements of the form {vali,False} are dropped, as are all elements after the first {vali,True}.
- Piecewise[conds] automatically evaluates to Piecewise[conds,0].
- Piecewise can be used in such functions as Integrate, Minimize, Reduce, DSolve, and Simplify, as well as their numeric analogs.
- Piecewise[{{v1,c1},{v2,c2},…}] can be input in the form
v1 c1 v2 c2 … - In StandardForm and TraditionalForm, Piecewise[{{v1,c1},{v2,c2},…}] is normally output using a brace, as in
v1 c1 v2 c2 …
Examples
open allclose allBasic Examples (3)
Scope (12)
Evaluate it at specific points:
Automatic simplification of Piecewise functions:
Remove False conditions:
Merge cases with the same values:
If values are not specified in a region, they are assumed to be zero:
This specifies that the default value should be 1:
Compute limits of piecewise functions:
Compute the limit in the direction of the positive imaginary axis:
Compute the series of a piecewise function:
Integrate a piecewise function:
Integration constants are chosen to make the result continuous:
Compute a definite integral of a piecewise function:
Laplace transform of a piecewise function:
Solve a piecewise differential equation:
Integrating an implicitly piecewise integrand can give an explicit Piecewise result:
Properties & Relations (11)
PiecewiseExpand converts nested piecewise functions into a single piecewise function:
Min, Max, UnitStep, and Clip are piecewise functions of real arguments:
Abs, Sign, and Arg are piecewise functions when their arguments are assumed to be real:
KroneckerDelta and DiscreteDelta are piecewise functions of complex arguments:
Boole is a piecewise function of a Boolean argument:
If, Which, and Switch can be interpreted as piecewise functions:
Convert Floor, Ceiling, Round, IntegerPart, and FractionalPart for finite ranges:
Convert Mod and Quotient when the number of cases is finite:
UnitBox and UnitTriangle are piecewise functions of real arguments:
Convert SquareWave, TriangleWave, and SawtoothWave for finite ranges:
BernsteinBasis and BSplineBasis are piecewise functions of real arguments:
Text
Wolfram Research (2004), Piecewise, Wolfram Language function, https://reference.wolfram.com/language/ref/Piecewise.html (updated 2008).
CMS
Wolfram Language. 2004. "Piecewise." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2008. https://reference.wolfram.com/language/ref/Piecewise.html.
APA
Wolfram Language. (2004). Piecewise. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Piecewise.html