ReferencepiecewiseFunction

<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>
AttributeTypeValues
applyStyleToLabel = "…"boolean"true" "false"
displayDecimals = "…"integer
displayDigits = "…"integer
displaySmallAsZero = "…"number
domain = "…"
expand = "…"text"true" "false"
labelIsName = "…"boolean"true" "false"
labelPosition = "…"text"upperright" "upperleft" "lowerright" "lowerleft" "top" "bottom" "left" "right"
layer = "…"number
nearestPointAsCurve = "…""true" "false"
padZeros = "…"boolean"true" "false"
simplify = "…"text"none" "full" "numbers" "numberspreserveorder"
symbolic = "…"boolean"true" "false"
throughSlopes = "…"
variable = "…"_variableName
variables = "…"[ _variableName ]
xscale = "…"number
yscale = "…"number
Props for <piecewiseFunction name="p">
PropertyType
$p.applyStyleToLabelboolean
$p.backgroundColortext
$p.disabledboolean
$p.displayDecimalsinteger
$p.displayDigitsinteger
$p.displaySmallAsZeronumber
$p.expandtext
$p.expandSpecifiedboolean
$p.extrema[ number ]
$p.fixedboolean
$p.fixLocationboolean
$p.formulamath
$p.globalInfimum[ number ]
$p.globalMaximum[ number ]
$p.globalMinimum[ number ]
$p.globalSupremum[ number ]
$p.hiddenboolean
$p.labellabel
$p.labelIsNameboolean
$p.labelPositiontext
$p.latexlatex
$p.layernumber
$p.maxima[ number ]
$p.minima[ number ]
$p.numExtremanumber
$p.numInputsinteger
$p.numMaximanumber
$p.numMinimanumber
$p.numOutputsinteger
$p.padZerosboolean
$p.simplifytext
$p.styleDescriptiontext
$p.styleDescriptionWithNountext
$p.symbolicboolean
$p.texttext
$p.textColortext
$p.textStyleDescriptiontext
$p.variable_variableName
$p.variables[ _variableName ]
$p.xscalenumber
$p.yscalenumber

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 macro.

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

  1. graphing the linear component of the function,
  2. for correctly rendering the equation of the piecewise function outside the graph, and
  3. 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 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 xx.


Property Example: minima/ maxima

Local maxima and minima of the <piecewiseFunction> are rendered with the maxima/minima properties.