2.6 ODE Solver

Summary

ODE Solver app is used to provide arithmetic solution for ordinary differential equations (ODE). It is widely used in mathematics and engineering.

ODE Solver app can solve a single ordinary differential equation or a system of equations. In this tutorial, we will show you both cases. For more examples, please click ⍰ button at the top-right corner of the app dialog or press F1 to open document.

Tutorial

Ordinary Differential Equation

Here we consider a nonlinear damped vibration system, that is, the object vibrates under the elastic force of a spring and a nonlinear damping force. The dynamic equation described this system can be written as follow, in which the damping force is in proportion to the square of the velocity:

\frac {d^{2}y}{d^{2}x}= -2\beta\frac{dy}{dx}- \omega^{2}y- \gamma (\frac{dy}{dx})^{2}

where x is time, y is the displacement of the object, y' is the velocity, y'' is acceleration, ω, β, γ are parameters. In this example, we take their values as follow:

omega = 1.0 // the natural frequency of the system,
beta = 0.1 // the linear damping coefficient
gamma = 0 // the nonlinear damping coefficient

The initial conditions at x0 = 0 are:

{y|_{x=x_0} \choose y'|_{x=x_0}} = {1 \choose 0}

We want to integrate the equation in the interval of [0,100].

  1. Click the ODE Solver icon ODE Solver icon.png in the Apps Gallery.
  2. In the opened dialog,
    • choose Equation,
    • enter 2 in the Order edit box,
    • enter the 2nd derivative expression as follow in y''= edit box:
      -y-2*0.1*y'-0.1*y'^2
    • in Integration Interval branch, enter Start Value = 0 and End Value = 100.
    • in Initial Conditions branch, enter y|x=x0 = 1 and y'|x=x0 = 0.
    • in Settings branch, make sure Method is set to Runge-Kutta and RK Order and Relative Tolerance are set as default.
    • check Output Derivatives and then check y' since we want to output object's velocity.
    ODE Solver 01.png

    Click OK button.
  3. A worksheet named ODE Solution and a graph window are created.
    • The worksheet contains a XY pair solved from the ordinary differential equation we specified above. The third column contains the first derivative.
    • The graph visualizes the output results in the worksheet, that is, displacement and velocity versus time. We can tell from it how nonlinear damping force effects on a vibrating system.
    ODE Solver 02.png

System of Ordinary Differential Equations

In the second example, we consider a classic ecological model: the Lotka-Volterra competition model:

\left( \begin{matrix}\frac{dN_1}{dt} \\\\ \frac{dN_2}{dt} \end{matrix}\right)
= \left( \begin{matrix} r_1N_1\left(1-\frac{N_1+a_{12}N_2}{K_1}\right) \\\\
r_2N_2\left(1-\frac{N_2+a_{21}N_1}{K_2}\right)\end{matrix}\right)

This equation system describes the competition between two species under limited resources. N1 and N2 are the population size of two species, r1, r2, K1, K2, a12 and a21 are parameters. In this example, we take their values as follow:

r1 = 1.0  // intrinsic growth rate of species 1
r2 = 1.5  // intrinsic growth rate of species 2
K1 = 10.0  // population size of species 1
K2 = 10.0  // population size of species 2
a12 = 0.3  // competition coefficient of species 1
a21 = 0.6  // competition coefficient of species 2

The initial conditions at x0 = 0 are:

{N_1|_{t=t_0} \choose N_2|_{t=t_0}} = {10 \choose 5}

We want to integrate the equation in the interval of [0,50].

  1. Click the ODE Solver icon ODE Solver icon.png in the Apps Gallery.
  2. In the opened dialog,
    • choose System of Equations,
    • enter 2 for Number of Equations,
    • enter equations as follow:
      dy1/dx = y1*(1-(y1+0.3*y2)/10) ,
      dy2/dx = 1.5*y2*(1-(y2+0.6*y1)/10) ,
    • in Integration Interval branch, enter Start Value = 0 and End Value = 50,
    • in Initial Conditions branch, enter y1|x=x0 = 10 and y2|x=x0 = 5,
    • in Settings branch, make sure Method is set to Runge-Kutta and RK Order and Relative Tolerance is set as default.
    ODE Solver 03.png

    Click OK button.
  3. A worksheet named ODE Solution and a graph window are created.
    • The worksheet contains XY1Y2 datasets solved from the equation system we specified above.
    • The graph visualizes the output results in the worksheet. That is, the changes in the population size of two species over time. We can tell from it that after years of competition for resources, the two species may reach a relatively stable "coexistence state".
    ODE Solver 04.png

Dialog Settings

Type
  • Equation
Solve ordinary differential equation
  • System of Equations
Solve system of first order differential equations
Order/Number of Equations If Equation is selected for Type, this specifies order of the differential equation.

If System of Equations is selected for Type, this specifies number of equations of the system.

Equation(s)

For differential equation, valid variables are x, y, y', y'',...,y^{(\text{Order}-1)}.

For system of differential equations, valid variables are x, y_1, y_2, ..., y_{\text{neq}} where neq is the number of equations.

Integration Interval

Start Value Specify start value of integration interval. This is the initial value of the independent variable.
End Value Specify end value of integration interval. End value should be different from start value.
Number of Points Specify number of points to output. The points are evenly sampled from the integration interval.

Initial Conditions

Specify initial conditions at the initial value of the independent variable. For differential equation, specify initial conditions for y, y', y'',...,y^{(\text{Order}-1)}. For system of differential equations, specify initial conditions for y_1, y_2, ..., y_{\text{neq}}.

Settings

Specify integration algorithm and error control

Method Specify integration algorithm. Available options include:
  • Runge-Kutta
Usually this is your first choice.
  • Adams
Adams method.
  • BDF(Stiff)
Backward Differentiation Formulae. This algorithm is suitable for stiff problems.
RK Order This is available only when Runge-Kutta has been selected for Method. Experience suggests:
RK Order Relative Tolerance
RK23 10^{-2}-10^{-4}
RK45 10^{-3}-10^{-6}
RK78 10^{-5}-
Relative Tolerance Specify a relative tolerance for controlling the error in the integration. It is available for Runge-Kutta and BDF(Stiff) methods.
Mixed Tolerance Specify a mixed tolerance for controlling the error in the integration. A mixed tolerance is defined as:
\sum_{i=1}^{neq} ( \frac{e_i}{ \tau|z_i| + \tau } )^2 \le 1

where neq is number of equations (system of equations) or order of the equation (ordinary differential equation), z_i is dependent variables (system of equations) or dependent variable and its derivatives (ordinary differential equation), e_i is an estimate of the local error at z_i and \tau is the specified mixed tolerance.

This option is available only in Adams method.

Output Derivatives

Specify derivatives to output. This branch is available only when Equation has been selected for Type and Order is larger than 1. User can choose whether to output derivatives y', y'',...,y^{(\text{Order}-1)}.

ODE Solution

Specify output worksheet for ODE solution.

Algorithm

  1. Algorithm for Runge-Kutta: nag_ode_ivp_rk_setup (d02pvc), nag_ode_ivp_rk_range (d02pcc).
  2. Algorithm for Adams: nag_ode_ivp_adams_gen (d02cjc).
  3. Algorithm for BDF(Stiff): nag_ode_ivp_bdf_gen (d02ejc).