<piecewiseFunction>
<piecewiseFunction> is a Graphical
component that renders a piecewise defined function that can be evaluated and graphed in the same manner
as a <function> component.
In order to evaluate a piecewiseFunction, the function attribute symbolic must be
set to false, to force numerical evaluation.
Disclaimer: currently, piecewise functions cannot be used with the <derivative> component.
Individual <function> children need to be differentiated independently. Open and closed
endpoints must also be graphed as independent components (see <endpoint>.)
Attributes and Properties
Attributes for <piecewiseFunction>
Number display (5)
avoidScientificNotationboolean. Default value: false. Whether to render numbers in full decimal form rather than scientific notation.
displayDecimalsinteger. Default value: 2. Number of decimal places to display when rendering this number.
displayDigitsinteger. Default value: 3. Number of significant digits to display when rendering this number.
displaySmallAsZeronumber. Default value: 1e-14. Threshold below which numbers are displayed as zero.
padZerosboolean. Default value: false. Whether to pad displayed numbers with trailing zeros to fill the requested digits/decimals.
Labels (1)
labelIsNameboolean. Default value: false. Whether to use this component's name as its rendered label.
Other (13)
applyStyleToLabelboolean. Default value: false. Whether to apply the function's style to its label.
intervalList. Restriction of the function's domain to a list of intervals.
expandboolean. Default value: false. Whether to expand the function's formula.
labelPositionkeyword. Position of the function's label.
| Value | Description |
|---|---|
upperRight (default) | Place the label above and to the right of the function curve. |
upperLeft | Place the label above and to the left of the function curve. |
lowerRight | Place the label below and to the right of the function curve. |
lowerLeft | Place the label below and to the left of the function curve. |
top | Place the label directly above the function curve. |
bottom | Place the label directly below the function curve. |
left | Place the label directly to the left of the function curve. |
right | Place the label directly to the right of the function curve. |
layernumber. Default value: 0. Z-order layer index for stacking the function on a graph.
nearestPointAsCurveboolean. Default value: false. Whether nearest-point queries should treat the function as a curve in the plane rather than a graph y = f(x).
simplifykeyword. Level of simplification applied to the function's formula.
| Value | Description |
|---|---|
none | No simplification is applied. |
full (default) | Fully simplify the function's formula. |
numbers | Simplify numeric subexpressions only, leaving symbolic structure intact. |
numbersPreserveOrder | Like numbers, but does not reorder commutative operands. |
normalizeOrder | Reorder commutative operands into a canonical form without simplifying values. |
symbolicboolean. Default value: true. Whether the function should be evaluated symbolically rather than numerically.
throughSlopesmathList. Slopes the interpolated function should have at each through-point.
_variableName. Name of the function's single input variable.
[ _variableNameList ]. Names of the function's input variables.
xscalenumber. Default value: 1. Scale factor used along the x-axis.
yscalenumber. Default value: 1. Scale factor used along the y-axis.
Common to all components (9)
copyreference. Create an independent copy of another component by reference. Enter a references a $name.
disabledboolean. Default value: false. Whether this component is disabled and cannot be interacted with.
extendreference. Extend another component by reference, inheriting its children and attributes. Enter a reference as $name.
fixedboolean. Default value: false. Whether this component's value is fixed and cannot be modified.
fixLocationboolean. Default value: false. Whether this component's location is fixed (preventing it from being moved while still allowing other modifications).
hideboolean. Default value: false. Whether to hide this component from the rendered output.
isResponseboolean. Default value: false. Whether this component is treated as a response for the purposes of assessment.
nametext. The name used to reference this component from elsewhere in the document.
styleNumberinteger. Default value: 1. The style number used to select this component's visual styling from the available style definitions.
Properties for <piecewiseFunction name="p">
Number display (5)
$p.avoidScientificNotationboolean. Whether to render numbers in full decimal form rather than scientific notation.
$p.displayDecimalsinteger. Number of decimal places to display when rendering this number.
$p.displayDigitsinteger. Number of significant digits to display when rendering this number.
$p.displaySmallAsZeronumber. Threshold below which numbers are displayed as zero.
$p.padZerosboolean. Whether to pad displayed numbers with trailing zeros to fill the requested digits/decimals.
Labels (2)
$p.labellabel. The label rendered with this component.
$p.labelIsNameboolean. Whether to use this component's name as its rendered label.
Other (41)
$p.applyStyleToLabelboolean. Whether to apply the function's style to its label.
$p.backgroundColortext. Human-readable name for this component's background color, derived from the active style and theme.
$p.disabledboolean. Whether this component is disabled and cannot be interacted with.
$p.expandtext. Whether to expand the formula.
$p.expandSpecifiedboolean. Whether to expand the function's formula.
$p.extrema[ number ]. Local extrema (minima + maxima) of the function.
$p.extremumLocations[ number ]. The x-coordinates of the function's local extrema.
$p.extremumValues[ number ]. The values of the function's local extrema.
$p.fixedboolean. Whether this component's value is fixed and cannot be modified.
$p.fixLocationboolean. Whether this component's location is fixed (preventing it from being moved while still allowing other modifications).
$p.formulamath. The piecewise formula of the function.
$p.globalInfimum[ number ]. The global infimum of the function.
$p.globalMaximum[ number ]. The global maximum of the function (if attained).
$p.globalMinimum[ number ]. The global minimum of the function (if attained).
$p.globalSupremum[ number ]. The global supremum of the function.
$p.labelPositiontext. Position of the function's label.
$p.latexlatex. The piecewise function rendered as a LaTeX string.
$p.layernumber. Z-order layer index for stacking the function on a graph.
$p.maxima[ number ]. Local maxima of the function.
$p.maximumLocations[ number ]. The x-coordinates of the function's local maxima.
$p.maximumValues[ number ]. The values of the function's local maxima.
$p.minima[ number ]. Local minima of the function.
$p.minimumLocations[ number ]. The x-coordinates of the function's local minima.
$p.minimumValues[ number ]. The values of the function's local minima.
$p.numExtremanumber. Number of local extrema (minima + maxima) of the function.
$p.numInputsinteger. Number of input variables.
$p.numMaximanumber. Number of local maxima of the function.
$p.numMinimanumber. Number of local minima of the function.
$p.numOutputsinteger. Number of output values.
$p.simplifytext. Level of simplification applied when displaying the formula.
$p.styleDescriptiontext. A textual description of the function's style.
$p.styleDescriptionWithNountext. Style description including the word "function".
$p.symbolicboolean. Whether the function is treated symbolically.
$p.texttext. The function rendered as a plain text string.
$p.textColortext. Human-readable name for this component's text color, derived from the active style and theme.
$p.textStyleDescriptiontext. Human-readable description of this component's text styling (color and any background color).
$p.variable_variableName. The function's first input variable name.
$p.variables[ _variableName ]. The names of the function's input variables.
$p.xscalenumber. Scale factor used along the x-axis.
$p.yscalenumber. Scale factor used along the y-axis.
Common to all components (4)
$p.doenetMLtext. The DoenetML source code that produced this component.
$p.hideboolean. Whether to hide this component from the rendered output.
$p.isResponseboolean. Whether this component is treated as a response for the purposes of assessment.
$p.styleNumberinteger. The style number used to select this component's visual styling from the available style definitions.
Examples
Example: A simple three-part <piecewiseFunction>
The <piecewiseFunction> component is defined by assigning <function> children
for each distinct region of the function’s domain. The named <piecewiseFunction> can
then be evaluated in the same manner as the <function> component using
the $$functionName(input) evaluation reference.
Note: When using a <piecewiseFunction> for evaluation, it is necessary to include
the function attribute symbolic="false" to force numerical evaluation.
Example: Adding endpoints graphically to a <piecewiseFunction>
Doenet only evaluates functions at points strictly in their specified domains. Therefore, in order to locate endpoints of open intervals for graphing, it may be necessary to define a set of base functions with unrestricted domains. In the example shown, the child functions themselves (and therefore the endpoint evaluations) are trivial, but the same method will work for more complex functions as well.
These predefined functions can then be copied into the definition of the <piecewiseFunction>
using the extend attribute, and the precise domains can be specified for each. This allows for
the single <piecewiseFunction> to then be used for
- graphing the linear component of the function,
- for correctly rendering the equation of the piecewise function outside the graph, and
- for correct mathematical evaluation at all points in the domain.
Note: When using a <piecewiseFunction> for evaluation, it is necessary to include the
function attribute symbolic="false" to force numerical evaluation.
Example: How domains are interpreted
Domains may be specified for the parent <piecewiseFunction>, and also for all individual child functions. When two domains overlap, the previously defined <function> governs. Finally, when no domain is specified for a given function, that function assumes the domain not occupied by all of the other defined functions.
Note: When using a <piecewiseFunction> for evaluation, it is necessary to include the function attribute symbolic="false" to force numerical evaluation.
Attribute Examples
Attribute Example: domain
The domain attribute can be used to specify an overarching domain
for the <piecewiseFunction>.
Attribute Example: variable/ variables
The variables attribute changes the overarching variable used for
the <piecewiseFunction>, but individual <function> variables may differ.
At this time (update forthcoming), the child functions will still look for a default
independent variable of .
Property Examples
Property Example: minima/ maxima
Local maxima and minima of the <piecewiseFunction> are rendered with the maxima/minima
properties.