ReferenceodeSystem

<odeSystem>

<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>
AttributeTypeValues
chunkSize = "…"number
displayDecimals = "…"integer
displayDigits = "…"integer
displaySmallAsZero = "…"number
hideInitialCondition = "…"boolean"true" "false"
independentVariable = "…"_variableName
initialConditions = "…"[ math ]
initialIndependentVariableValue = "…"math
maxIterations = "…"number
number = "…"boolean"true" "false"
padZeros = "…"boolean"true" "false"
renderMode = "…"text
tolerance = "…"number
variables = "…"[ _variableName ]
Props for <odeSystem name="o">
PropertyType
$o.backgroundColortext
$o.chunkSizenumber
$o.disabledboolean
$o.displayDecimalsinteger
$o.displayDigitsinteger
$o.displaySmallAsZeronumber
$o.equationTagtext
$o.fixedboolean
$o.fixLocationboolean
$o.hiddenboolean
$o.hideInitialConditionboolean
$o.independentVariable_variableName
$o.initialConditionmath
$o.initialConditions[ math ]
$o.initialIndependentVariableValuemath
$o.latexlatex
$o.maxIterationsnumber
$o.numberboolean
$o.numericalSolutionfunction
$o.numericalSolutions[ function ]
$o.padZerosboolean
$o.renderModetext
$o.rhsmath
$o.rhss[ math ]
$o.righthandsidemath
$o.righthandsides[ math ]
$o.textColortext
$o.textStyleDescriptiontext
$o.tolerancenumber
$o.variables[ _variableName ]

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 $&dollar;functionName(input) evaluation macro 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 where ,

<me>\frac{d^2 \theta}{d t^2} + \frac{g}{l} \sin(\theta) = 0</me>

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 $\frac{d^2 \theta}{d t^2} = \frac{d \omega}{d t}$ results in a first-order system of two equations,
<md>
<mrow>\frac{d \theta}{d t} &= \omega</mrow>
<mrow>\frac{d \omega}{d t}  &= - \frac{g}{l} \sin(\theta).</mrow>
</md>



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



---

### Example: Animated simple pendulum - simulation


```doenet-editor-horiz
<odesystem name="pendulum" hideInitialCondition variables="theta omega" initialConditions="1 1" maxIterations="10000">
  <rightHandSide>omega</rightHandSide>
  <rightHandSide>-20 sin(theta)</rightHandSide>
</odesystem>

  <function copySource="pendulum.numericalsolution1" name="thetaFn"/>
  <function copySource="pendulum.numericalsolution2" name="omegaFn" />

<p>State of the pendulum</p>
<p>t = <number name="t">0</number></p>
<p><m>\theta($t) = 
<wrapnumberperiodic name="theta" lowervalue="-pi" uppervalue="pi">
  $$thetaFn($t)
</wrapnumberperiodic>
</m></p>
<p><m>\omega($t) = <math name="omega">$$omegaFn($t)</math></m></p>
<p>Scroll down to view the animated simulation.</p>
<animatefromsequence hide target="t" from="0" step="0.1" to="10" animationInterval="100" name="animate" />
<callAction actionName="startAnimation" target="animate"  ><label>Start animation</label></callAction>
<callAction actionName="stopAnimation" target="animate"  ><label>Stop animation</label></callAction>
<p>Simulation</p>
  <graph displayXaxis="false" displayYaxis="false" xmin="-1" xmax="1" ymin="-1" ymax="1" fixAxes>
    <point name="mid" fixed="true" styleNumber="4">(0,0)</point>
    <point name="end" fixed x="0.5 sin($theta)" y="-0.5 cos($theta)" hide />
    <linesegment endpoints="$mid $end" fixed styleNumber="4"/>
    <circle radius="0.08" center="$end" filled styleNumber="4" />
    <angle radius="0.25" through="$end $mid (0,-1)">
      <label><m>\theta=$theta</m></label>
    </angle>  
</graph>

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 copySource attribute.