ReferenceclampFunction

<clampFunction>

A function clamped to a specified output range

<clampFunction> is a Math Operator that wraps a <function> and limits its output to a closed interval [lowerValue,upperValue][\text{lowerValue}, \text{upperValue}]. Any output below lowerValue is replaced by lowerValue; any output above upperValue is replaced by upperValue. The default interval is [0,1][0, 1].

The result is itself a function, so it can be evaluated, graphed, and used anywhere an ordinary <function> is accepted. Compare with <clampNumber>, which clamps a single number rather than a function, and with <wrapFunctionPeriodic>, which wraps a function’s output instead of clamping it.

Attributes and Properties

Attributes for <clampFunction>

Number display (5)
avoidScientificNotation

boolean. Default value: false. Whether to render numbers in full decimal form rather than scientific notation.

displayDecimals

integer. Default value: 2. Number of decimal places to display when rendering this number.

displayDigits

integer. Default value: 3. Number of significant digits to display when rendering this number.

displaySmallAsZero

number. Default value: 1e-14. Threshold below which numbers are displayed as zero.

padZeros

boolean. Default value: false. Whether to pad displayed numbers with trailing zeros to fill the requested digits/decimals.

Labels (1)
labelIsName

boolean. Default value: false. Whether to use this component's name as its rendered label.

Other (21)
applyStyleToLabel

boolean. Default value: false. Whether to apply the function's style to its label.

domain

[ intervalList ]. Restriction of the function's domain to a list of intervals.

expand

boolean. Default value: false. Whether to expand the function's formula.

extrema

[ extrema ]. Local extrema (combined minima and maxima) of an interpolated function.

labelPosition

keyword. Position of the function's label.

ValueDescription
upperRight (default)Place the label above and to the right of the function curve.
upperLeftPlace the label above and to the left of the function curve.
lowerRightPlace the label below and to the right of the function curve.
lowerLeftPlace the label below and to the left of the function curve.
topPlace the label directly above the function curve.
bottomPlace the label directly below the function curve.
leftPlace the label directly to the left of the function curve.
rightPlace the label directly to the right of the function curve.
layer

number. Default value: 0. Z-order layer index for stacking the function on a graph.

number. Default value: 0. Lower bound for the operator's range.

maxima

[ extrema ]. Local maxima of an interpolated function.

minima

[ extrema ]. Local minima of an interpolated function.

nearestPointAsCurve

boolean. Default value: false. Whether nearest-point queries should treat the function as a curve in the plane rather than a graph y = f(x).

numInputs

integer. Number of input arguments the function accepts.

numOutputs

integer. Default value: 1. Number of output values the function produces.

simplify

keyword. Level of simplification applied to the function's formula.

ValueDescription
noneNo simplification is applied.
full (default)Fully simplify the function's formula.
numbersSimplify numeric subexpressions only, leaving symbolic structure intact.
numbersPreserveOrderLike numbers, but does not reorder commutative operands.
normalizeOrderReorder commutative operands into a canonical form without simplifying values.
symbolic

boolean. Default value: true. Whether the function should be evaluated symbolically rather than numerically.

through

pointList. Points the interpolated function should pass through.

throughSlopes

mathList. Slopes the interpolated function should have at each through-point.

number. Default value: 1. Upper bound for the operator's range.

variable

_variableName. Name of the function's single input variable.

variables

[ _variableNameList ]. Names of the function's input variables.

xscale

number. Default value: 1. Scale factor used along the x-axis.

yscale

number. Default value: 1. Scale factor used along the y-axis.

Common to all components (9)
copy

reference. Create an independent copy of another component by reference. Enter a references a $name.

disabled

boolean. Default value: false. Whether this component is disabled and cannot be interacted with.

extend

reference. Extend another component by reference, inheriting its children and attributes. Enter a reference as $name.

fixed

boolean. Default value: false. Whether this component's value is fixed and cannot be modified.

fixLocation

boolean. Default value: false. Whether this component's location is fixed (preventing it from being moved while still allowing other modifications).

hide

boolean. Default value: false. Whether to hide this component from the rendered output.

isResponse

boolean. Default value: false. Whether this component is treated as a response for the purposes of assessment.

name

text. The name used to reference this component from elsewhere in the document.

styleNumber

integer. Default value: 1. The style number used to select this component's visual styling from the available style definitions.

Properties for <clampFunction name="c">

Number display (5)
$c.avoidScientificNotation

boolean. Whether to render numbers in full decimal form rather than scientific notation.

$c.displayDecimals

integer. Number of decimal places to display when rendering this number.

$c.displayDigits

integer. Number of significant digits to display when rendering this number.

$c.displaySmallAsZero

number. Threshold below which numbers are displayed as zero.

$c.padZeros

boolean. Whether to pad displayed numbers with trailing zeros to fill the requested digits/decimals.

Labels (2)
$c.label

label. The label rendered with this component.

$c.labelIsName

boolean. Whether to use this component's name as its rendered label.

Other (44)
$c.applyStyleToLabel

boolean. Whether to apply the function's style to its label.

$c.backgroundColor

text. Human-readable name for this component's background color, derived from the active style and theme.

$c.disabled

boolean. Whether this component is disabled and cannot be interacted with.

$c.domain

[ interval ]. Domain interval(s) of the function.

$c.expand

text. Whether to expand the formula.

$c.expandSpecified

boolean. Whether to expand the function's formula.

$c.extrema

[ number ]. Local extrema (minima + maxima) of the function.

$c.extremumLocations

[ number ]. The x-coordinates of the function's local extrema.

$c.extremumValues

[ number ]. The values of the function's local extrema.

$c.fixed

boolean. Whether this component's value is fixed and cannot be modified.

$c.fixLocation

boolean. Whether this component's location is fixed (preventing it from being moved while still allowing other modifications).

$c.formula

math. The symbolic formula of the function produced by this operator.

$c.globalInfimum

[ number ]. The global infimum of the function.

$c.globalMaximum

[ number ]. The global maximum of the function (if attained).

$c.globalMinimum

[ number ]. The global minimum of the function (if attained).

$c.globalSupremum

[ number ]. The global supremum of the function.

$c.hidden

boolean. Whether this component is hidden from the rendered output.

$c.labelPosition

text. Position of the function's label.

$c.latex

latex. The function rendered as a LaTeX string.

$c.layer

number. Z-order layer index for stacking the function on a graph.

$c.lowerValue

number. Lower bound for the operator's range.

$c.maxima

[ number ]. Local maxima of the function.

$c.maximumLocations

[ number ]. The x-coordinates of the function's local maxima.

$c.maximumValues

[ number ]. The values of the function's local maxima.

$c.minima

[ number ]. Local minima of the function.

$c.minimumLocations

[ number ]. The x-coordinates of the function's local minima.

$c.minimumValues

[ number ]. The values of the function's local minima.

$c.numExtrema

number. Number of local extrema (minima + maxima) of the function.

$c.numInputs

integer. Number of input variables of the function.

$c.numMaxima

number. Number of local maxima of the function.

$c.numMinima

number. Number of local minima of the function.

$c.numOutputs

integer. Number of output values of the function.

$c.simplify

text. Level of simplification applied when displaying the formula.

$c.styleDescription

text. A textual description of the function's style.

$c.styleDescriptionWithNoun

text. Style description including the word "function".

$c.symbolic

boolean. Whether the function is treated symbolically.

$c.text

text. The function rendered as a plain text string.

$c.textColor

text. Human-readable name for this component's text color, derived from the active style and theme.

$c.textStyleDescription

text. Human-readable description of this component's text styling (color and any background color).

$c.upperValue

number. Upper bound for the operator's range.

$c.variable

_variableName. The function's first input variable name.

$c.variables

[ _variableName ]. The names of the function's input variables.

$c.xscale

number. Scale factor used along the x-axis.

$c.yscale

number. Scale factor used along the y-axis.

Common to all components (4)
$c.doenetML

text. The DoenetML source code that produced this component.

$c.hide

boolean. Whether to hide this component from the rendered output.

$c.isResponse

boolean. Whether this component is treated as a response for the purposes of assessment.

$c.styleNumber

integer. The style number used to select this component's visual styling from the available style definitions.

Examples

Example: Clamp a function to [0,1][0, 1]

The underlying function f(x) = x/4 is plotted alongside its clamp. Outside the input range [0,4][0, 4] the clamped function flatlines at 00 or 11.


Example: Use as part of a graph

Setting lowerValue and upperValue clamps sin(x) to a band of width 11, flattening the peaks and troughs. The original function is plotted underneath for comparison.


Example: Evaluate a clamped function at specific inputs

The named clamp is evaluated like any other function with $$name(input). Outputs inside [0,5][0, 5] pass through unchanged; outputs outside it are replaced by the nearest endpoint.

Attribute Examples

Attribute Example: lowerValue, upperValue

lowerValue and upperValue set the output interval. The clamped function is constant outside the input range where the underlying function is below lowerValue or above upperValue.