Piecewise
Usage
Notes
Further Examples
Piecewise Definition and Evaluation This defines a piecewise function.
In[1]:=
|
Here is the plot.
In[2]:=
|
Here is a simplification.
In[3]:=
|
Out[3]=
|
Expansions Any nested combination of piecewise functions can be expanded into a single piecewise function, the so-called piecewise normal form.
In[4]:=
|
Out[4]=
|
Piecewise Functions with a Finite Number of Cases Max and Min have two piecewise cases. Here is a composition that is expanded into piecewise normal form.
In[5]:=
|
Out[5]=
|
Here the expansion will only happen if the variables are assumed to be real, since for complex arguments Abs is not a piecewise function.
In[6]:=
|
Out[6]=
|
Piecewise Functions with an Infinite Number of Cases Floor, Ceiling, FractionalPart and IntegerPart can have arbitrarily many piecewise cases.
In[7]:=
|
Out[7]=
|
Here an explicit finite range for the variable x needs to be given.
In[8]:=
|
Out[8]=
|
Piecewise Equations and Inequalities You can solve equations, inequalities, and do quantifier elimination of expressions involving piecewise functions. This solves two inequalities.
In[9]:=
|
Out[9]=
|
This solves an equation.
In[10]:=
|
Out[10]=
|
This finds a particular solution to a system of inequalities and an equation.
In[11]:=
|
Out[11]=
|
This finds the conditions on such that the resulting inequalities have a solution.
In[12]:=
|
Out[12]=
|
Piecewise Optimization This minimizes a piecewise function over an interval.
In[13]:=
|
Out[13]=
|
This maximizes a nested piecewise function over piecewise defined inequalities.
In[14]:=
|
Out[14]=
|
Piecewise Derivatives Here is a derivative of a piecewise function. The derivative is Indeterminate at the origin, since the derivative does not exist there.
In[15]:=
|
Out[15]=
|
The Sinc function has a derivative at each point including the origin.
In[16]:=
|
In[17]:=
|
Out[17]=
|
Here a piecewise function is expanded and the derivative is given on the interior of each segment.
In[18]:=
|
Out[18]=
|
Piecewise Limit In general piecewise functions have jump discontinuities, so directional limits may differ.
In[19]:=
|
Out[19]=
|
In[20]:=
|
Out[20]=
|
Piecewise Series Here the series around is well defined.
In[21]:=
|
Out[21]=
|
Here the series around is well defined.
In[22]:=
|
Out[22]=
|
Piecewise Indefinite Integrals Here is the integral of a piecewise function.
In[23]:=
|
Out[23]=
|
This function cannot be integrated over the complex numbers since Abs does not have an antiderivative.
In[24]:=
|
Out[24]=
|
However the function can be integrated over the reals because the antiderivative of Abs[x] is .
In[25]:=
|
Out[25]=
|
See also the Further Examples for Integrate. Piecewise Definite Integrals over Regions When integrating over a region defined by logical combinations of inequalities it is often convenient to use the piecewise function Boole. The complexity depends not only on the function to be integrated, but also on the complexity of the region. In the following example there are three fundamentally different cases: 1) the region is bounded by a hyperbola that contains the unit square, 2) the region is bounded by an ellipse completely contained in the unit square, 3) the region is bounded by the intersection of an ellipse and the unit square.
In[26]:=
|
Out[26]=
|
Here there are only two cases, but in general having parameters in region descriptions can generate a large number of cases.
In[27]:=
|
Out[27]=
|
Here the region is defined by a transcendental inequality.
In[28]:=
|
Out[28]=
|
Here there are infinitely many intervals defined by the inequalities.
In[29]:=
|
Out[29]=
|
See also the Further Examples for Integrate. General Piecewise Definite Integrals This piecewise function has discontinuities in the interval from to .
In[30]:=
|
Here is its integral.
In[31]:=
|
Out[31]=
|
This integrates a nested piecewise function over a rectangle.
In[32]:=
|
Out[32]=
|
You can also integrate many other types of piecewise functions.
In[33]:=
|
Out[33]=
|
Here there are nested piecewise functions both in the integrand and in the region description.
In[34]:=
|
Out[34]=
|
Some of these integrals can be quite involved.
In[35]:=
|
Out[35]=
|
See also the Further Examples for Integrate. Piecewise Differential Equations You can solve piecewise differential equations. In this example there is a piecewise function of the independent variable.
In[36]:=
|
Out[36]=
|
Here is another example.
In[37]:=
|
Out[37]=
|
|