TOPICS
Search

Piecewise Function


A piecewise function is a function specified by different formulas on different parts of its domain. A common example is the absolute value,

 |x|={-x   for x<0; 0   for x=0; x   for x>0.
(1)

Piecewise functions are implemented in the Wolfram Language as Piecewise[{{val1, cond1}, {val2, cond2}, ...}].

Additional piecewise functions include the Heaviside step function, rectangle function, and triangle function.

For a real argument x, suppose the formulas f_0(x),...,f_m(x) apply from left to right, with breakpoints a_1<...<a_m assigned to the pieces on their right. If each formula is defined on the whole domain, the piecewise function can be written as

 f(x)=f_0(x)+sum_(j=1)^mH(x-a_j)[f_j(x)-f_(j-1)(x)],
(2)

where H(x) is the Heaviside step function with H(0)=1. On each interval the active terms telescope to its formula (Oldham and Spanier 1974, §6.9).

On the interior of each piece, ordinary differentiation uses the formula for that piece. For a real-variable function with finitely many pieces that extend to continuously differentiable functions on their closures, being differentiable at an interior boundary requires continuity and agreement of the one-sided derivatives. Under the same piecewise regularity assumption, each jump discontinuity contributes a delta function, multiplied by the jump size, to the derivative in the sense of generalized functions. Merely differentiating the separate formulas omits these contributions (Trott 2006).

Semicolons and commas are sometimes used at the end of either the left or the right column, with particular usage apparently depending on the author. The words "if" and "for" are sometimes used in the right column, as is "otherwise" for the final (default) case.

For example, Knuth (1996, pp. 175 and 180) uses the notations

|x|={x, if x>=0;; -x, otherwise;
(3)
f(x)={1/3 if 0<=x<=1;; 2/3 if 3<=x<=4;; 0 elsewhere
(4)
x_(2m)={Q(X_m^2-P_2W_m^2)-2S^2 (m odd); P_2^2(X_m^2-P_2W_m^2)-2S^2 (m even)
(5)

both with and without the left-column commas. Similarly, Arfken (1985, pp. 488-489) uses

 delta_n(x)={0,   x<-1/(2n); n,   -1/(2n)<x<1/(2n); 0,   1/(2n)<x
delta_n(x)={0,   x<0; ne^(-nx),   x>0
lim_(a->infty)2/piint_(x_1)^(x_2)f(u+x)(sin(ax))/xdx
 ={f(u+0)+f(u-0),   x_1<0<x_2; f(u+0),   x_1=0<x_2; f(u-0),   x_1<0=x_2; 0   x_1<x_2<0 or 0<x_1<x_2,
(6)

which lacks semicolons but only sometimes lacks right-column commas.

In this work, commas and semicolons are not used.


See also

Derivative, Generalized Function, Heaviside Step Function, Iverson Bracket, Piecewise Constant Function, Piecewise Linear Function, Weak Derivative

Explore with Wolfram|Alpha

References

Arfken, G. Mathematical Methods for Physicists, 3rd ed. Orlando, FL: Academic Press, 1985.Knuth, D. E. The TEXBook. Boston, MA: Addison-Wesley, 1996.Oldham, K. B. and Spanier, J. "Differintegration of More Complex Functions." Ch. 6 in The Fractional Calculus: Theory and Applications of Differentiation and Integration to Arbitrary Order. New York: Academic Press, pp. 93-113, 1974. https://doi.org/10.1016/S0076-5392(09)60228-9. Rytin, M. "Integration of Piecewise Functions with Applications." https://library.wolfram.com/infocenter/MathSource/5117/.Trott, M. "Differentiation." §1.6.1 in The Mathematica GuideBook for Symbolics. New York: Springer-Verlag, 2006. https://doi.org/10.1007/0-387-28815-5. https://www.mathematicaguidebooks.org/.

Referenced on Wolfram|Alpha

Piecewise Function

Cite this as:

Weisstein, Eric W. "Piecewise Function." From MathWorld--A Wolfram Resource. https://mathworld.wolfram.com/PiecewiseFunction.html

Subject classifications