ReferenceodeSystem

<odeSystem>

A system of first-order ordinary differential equations with initial conditions, rendered as math and numerically integrable

<odeSystem> computes a numerical solution to a system of ordinary differential equations. The following are required attributes: variables and initialConditions. The opening <odeSystem> tag defines a block in which to enter one or more <rightHandSide> children, representing the successive RHS’s of the equations defining the system.

Attributes and Properties

Attributes for <odeSystem>

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.

Other (10)
chunkSize

number. Default value: 10. Step-size chunk used when numerically integrating the system.

hideInitialCondition

boolean. Default value: false. Whether to hide the initial condition from the rendered output.

independentVariable

_variableName. Default value: \(t\). The independent variable of the ODE system.

initialConditions

[ mathList ]. The initial values of each dependent variable, in order.

initialIndependentVariableValue

math. Default value: \(0\). The value of the independent variable at which the initial conditions are specified.

maxIterations

number. Default value: 1000. Maximum number of iterations the integrator may perform.

number

boolean. Default value: false. Whether to display equation numbers next to each equation.

renderMode

text. Default value: align. How to format the rendered system of equations (e.g. "align").

tolerance

number. Default value: 0.000001. Numerical tolerance used by the integrator.

variables

[ _variableNameList ]. The dependent variables of the system, in the same order as the right-hand sides.

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 <odeSystem name="o">

Number display (5)
$o.avoidScientificNotation

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

$o.displayDecimals

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

$o.displayDigits

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

$o.displaySmallAsZero

number. Threshold below which numbers are displayed as zero.

$o.padZeros

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

Other (26)
$o.backgroundColor

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

$o.chunkSize

number. Step-size chunk used when numerically integrating the system.

$o.disabled

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

$o.equationTag

text. The displayed equation number tag (when equation numbering is enabled).

$o.fixed

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

$o.fixLocation

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

$o.hidden

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

$o.hideInitialCondition

boolean. Whether to hide the initial condition from the rendered output.

$o.independentVariable

_variableName. The independent variable of the ODE system.

$o.initialCondition

math. The initial value of the first dependent variable at the initial independent-variable value.

$o.initialConditions

[ math ]. The initial values of each dependent variable at the initial independent variable value.

$o.initialIndependentVariableValue

math. The value of the independent variable at which the initial conditions are specified.

$o.latex

latex. The full ODE system rendered as a LaTeX string.

$o.maxIterations

number. Maximum number of iterations the integrator may perform.

$o.number

boolean. Whether to display equation numbers next to each equation.

$o.numericalSolution

function. Numerical solution function for the first dependent variable, as a function of the independent variable.

$o.numericalSolutions

[ function ]. Numerical solution functions for each dependent variable, as functions of the independent variable.

$o.renderMode

text. How to format the rendered system of equations (e.g. "align").

$o.rhs

math. The right-hand-side expression of the first ODE in the system.

$o.rhss

[ math ]. The right-hand-side expressions of each ODE in the system.

$o.righthandside

math. The right-hand-side expression of the first ODE in the system.

$o.righthandsides

[ math ]. The right-hand-side expressions of each ODE in the system.

$o.textColor

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

$o.textStyleDescription

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

$o.tolerance

number. Numerical tolerance used by the integrator.

$o.variables

[ _variableName ]. The dependent variables of the system, in order matching the right-hand sides.

Common to all components (4)
$o.doenetML

text. The DoenetML source code that produced this component.

$o.hide

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

$o.isResponse

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

$o.styleNumber

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

Examples

Example: Single ODE system with user-input

The required attributes as well as the <rightHandSide> child of the <odeSystem> component for a single differential equation are retrieved from user input. A <function> is then defined by accessing the numericalSolution property of the named <odeSystem> component. The solution can be graphed and evaluated in this manner using typical function evaluation techniques (i.e. by using either the $$functionName(input) evaluation reference or the <evaluate> component.)


Example: A spring-mass ODE system problem with validation

A linear spring-mass system is modeled as a <odeSystem> with two <rightHandSide> children. The problem is customizable via math inputs embedded in the problem statement. Note that, given the numerical nature of the solution process for the <odeSystem> component, an error allowance must be provided in the <answer> component using the allowedErrorInNumbers attribute.


Example: A simple pendulum ODE System

This example illustrates the use of <odeSystem> for a second-order nonlinear differential equation arising from the motion of a simple pendulum without damping

d2θdt2+glsin(θ)=0\frac{d^2 \theta}{d t^2} + \frac{g}{l} \sin(\theta) = 0

where θ\theta is the angle of the pendulum, gg is the acceleration due to gravity, and ll is the length of the pendulum.

Making the substitution d2θdt2=dωdt\frac{d^2 \theta}{d t^2} = \frac{d \omega}{d t} results in a first-order system of two equations,

dθdt=ωdωdt=glsin(θ).\begin{align*} \frac{d \theta}{d t} &= \omega\\ \frac{d \omega}{d t} &= - \frac{g}{l} \sin(\theta). \end{align*}

The right-hand side of these two equations are entered into the <odeSystem> component as <rightHandSide> children. The order of the children should match the order of the independent variables listed in the variables attribute of the <odeSystem> component definition. In this example, we have variables="theta omega", so the right-hand side equation for dθdt\frac{d \theta}{d t} is listed as the first child, and the right-hand side for dωdt\frac{d \omega}{d t} is listed as the second child.


Example: Animated simple pendulum - simulation

Refer to the previous example for the setup of the <odeSystem> component for this problem. In this example, the time parameter defined by the <number> t is animated with the <animateFromSequence/> component, which in turn animates θ(t)\theta(t). The simulated pendulum illustrates the angle.


Example: Animated simple pendulum - phase plane

Refer to the example titled “A simple pendulum ODE system” for the setup of the <odeSystem> component for this problem. In this example, the time parameter defined by the <number> t is animated with the <animateFromSequence/> component, which in turn animates θ(t)\theta(t) and ω(t)\omega(t). The nullcline of the phase plane is then graphed as a parametric <curve> with the horizontal coordinate given by the numerical solution for θ(t)\theta(t) and the vertical coordinate given by the numerical solution for ω(t)\omega(t).


Example: Animated simple pendulum - angle v. time

A point moving along the θ  v.  t\theta \;v.\; t function corresponding to the pendulum’s motion from the previous example is rendered on a <graph> by animating the time parameter defined by the <number> t.


Example: independentVariable

The default independent variable is tt. To employ a different independent variable, use the independentVariable attribute.


Example: initialIndependentVariableValue

The default initial value for the independent variable is 00. To employ a different initial value, use the initialIndependentVariableValue attribute.


Example: chunkSize

The solution to an ODE is calculated numerically in batches of the size given by the chunkSize attribute, which defaults to 1010. Each chunk is an interval where the independent variable changes by chunkSize. For each chunk, the numerical algorithm will use as many iterations as needed (up to the maximum number of iterations determined by the maxIterations attribute) to a achieve an error tolerance determined by the tolerance attribute. If this tolerance is not achieved, the evaluation of numerical solutions returns NaN. The algorithm may be able to integrate to larger values of the independent variable by increasing maxIterations or decreasing chunkSize (or by increasing tolerance).


Example: tolerance

The tolerance attribute may be adjusted to obtain convergence of solutions if the default tolerance of 10610^{-6} is inadequate. (For example, try evaluating f(20)f(20) in the example above.) The tolerance is the acceptable relative local error for the solution.

If solutions do not converge for the specified combination of solution parameters, including the tolerance attribute, the evaluation of numerical solutions returns NaN.


Example: maxIterations

The maxIterations attribute may be adjusted to obtain convergence of solutions if the default number of iterations (10001000) is inadequate for the desired tolerance. (For example, try evaluating f(20)f(20) in the example above.)

If solutions do not converge for the specified combination of solution parameters, including the maxIterations attribute, the evaluation of numerical solutions returns NaN.

The maxIterations attribute is the maximum number of iterations the solution algorithm will attempt to achieve the prescribed tolerance for each batch of the size given by chunkSize. For this reason, one can also decrease chunkSize to help achieve the required tolerance.


Example: hideInitialCondition

Use the hideInitialCondition attribute to suppress rendering of the required initial condition specification below the differential equations.


Example: initialConditions

The initialConditions attribute is required for the <odeSystem> component. Initial conditions for each dependent variable should be listed in the attribute in the same order that the associated equations appear as <rightHandSide> children in the <odeSystem> block.


Example: variables

The variables attribute is required for the <odeSystem> component. Each dependent variable should be listed in the variables attribute in the same order that the associated equations appear as <rightHandSide> children in the <odeSystem> block.


Example: Attributes as properties

The attributes listed in the example above are also available as properties.


Example: rhss

The rhss property stores/renders the right-hand side children of the <odeSystem> in an array.


Example: latex

The latex property stores/renders the LaTeX of the <odeSystem>.


Example: numericalSolutions

The numericalSolutions property is an array of functions corresponding to numerical solutions for each dependent variable in the system. To access the computed solutions of the system, use function evaluation with $odeSystemName.numericalSolutions[i] for the ithi^{th} function, or define new functions referencing the numericalSolution[i] property with the extend attribute.