TOPICS
Search

Piecewise Function


A piecewise function is a function that is defined on a sequence of intervals. 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.

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;
(2)
f(x)={1/3 if 0<=x<=1;; 2/3 if 3<=x<=4;; 0 elsewhere
(3)
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)
(4)

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,
(5)

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

In this work, commas and semicolons are not used.


See also

Heaviside Step Function, Iverson Bracket, Piecewise Constant Function, Piecewise Linear Function

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. Rytin, M. "Integration of Piecewise Functions with Applications." http://library/infocenter/MathSource/5117.

Referenced on Wolfram|Alpha

Piecewise Function

Cite this as:

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

Subject classifications