piecewise(cond_1, f_1, cond_2, f_2, ..., cond_n, f_n, f_otherwise)
relation or boolean combination of inequalities
(optional) default expression
With the piecewise function it is possible to express piecewise-continuous functions. The semantics are as in a case statement: if cond_1 is true then f_1, else if cond_2 is true then f_2, and so on. f_otherwise gives a default case which corresponds to all conditions being false. The default for f_otherwise is 0.
A condition can be a single equality or inequality, or a boolean combination of inequalities, such as x<3 or 0<x≤π. Equalities cannot be used in a boolean expression. The conditions can contain relations with polynomials, abs, signum, or piecewise functions, such as 0<x2−4and0<x or x<4. In all cases, x is assumed to be a real variable.
The piecewise function can be differentiated, integrated, simplified, plotted, and used in the following types of differential equations: constant coefficients and discontinuous perturbation function, general first-order linear, Riccati, and some other classes which are handled by integration or variation of parameter. See dsolve[piecewise] for more details. series, limit, abs, and signum can handle the piecewise function.
If parameters are involved in the conditions, the system requires useful assumptions in order to perform computations. For example, piecewise(a*x<1,f(x)) cannot be manipulated unless Maple can determine whether a is positive or negative using the assume system. See "What Assumptions" in the Context Panel.
There exist convert procedures to convert a piecewise function to an expression containing the Heaviside function and vice versa. A piecewise function can also be converted to a list representation, called pwlist. Expressions containing abs or signum can be converted to piecewise functions.
To enter a piecewise function in 2-D Math notation, you can use either the palettes or command completion. To add an additional line to this piecewise function, press Ctrl + Shift + R. See 2-D Math Shortcut Keys and Hints for more information.
The piecewise function evaluates its arguments on an as-needed basis. For example, if the first argument of a 3-argument call evaluates to true, the second argument is then evaluated and returned; the third argument is never evaluated.
An exception to the above is if piecewise is passed a single argument. That argument is evaluated, and if it yields an expression sequence, the members of that sequence are used as the actual arguments to piecewise. No further evaluation of the arguments takes place.
eq1 ≔ piecewise⁡4<x2andx<8,f⁡x
Piecewise functions can have parameters in the conditions.
eq2 ≔ piecewise⁡a<xandx<b,1,b<xandx<c,2
eq3 ≔ piecewise⁡0<x⁢d−2,1,2
Note that logical operators, involved in the piecewise conditions, are evaluated according to the same rules as used by the evalb command
As an alternative, use the inert functions And, Or, and Not to construct boolean expressions involving multiple conditions
f ≔ piecewise⁡Or⁡x=0,x=1,a,b
g ≔ piecewise⁡And⁡x≠0,0<y,a,b
h ≔ piecewise⁡And⁡n::integer,3<n,n2,n3
Piecewise functions can be simplified
p ≔ piecewise⁡x<0,−x,0<x,x
eq4 ≔ p2+5
l ≔ piecewise⁡x<0,x2,0<x,x
eq5 ≔ l2+5
However, if a piecewise function contains parameters, it cannot be simplified directly.
m ≔ piecewise⁡x<a,x,b<x,x2
eq6 ≔ simplify⁡m2
Other operations involving piecewise functions.
k ≔ x→piecewise⁡x<0,−1,x<1,0,1
j ≔ piecewise⁡x<0,−x2,0<x,x2
Download Help Document
What kind of issue would you like to report? (Optional)