Skip to main content

Numerical Integration of Ordinary Differential Equations

  • Chapter
  • First Online:
  • 6184 Accesses

Part of the book series: Lecture Notes in Bioengineering ((LNBE))

Abstract

This chapter presents an overview of numerical integration techniques for solving ODE systems, as implemented in Matlab and COMSOL. These techniques are broadly classified into one-step and multistep methods. One-step methods include forward and backward Euler, Runge–Kutta as well as generalized-\(\alpha \) methods, whilst multistep algorithms include the predictor-corrector schemes as well as the backward differentiation and numerical differentiation formula (BDF/NDF) methods. The chapter ends with problems with fully-worked answers in the Solutions section of the text.

This is a preview of subscription content, log in via an institution.

Buying options

Chapter
USD   29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD   189.00
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD   249.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info
Hardcover Book
USD   249.99
Price excludes VAT (USA)
  • Durable hardcover edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Learn about institutional subscriptions

Notes

  1. 1.

    Pronounced forward-Oiler.

  2. 2.

    Pronounced Run-ghee Cut-ah.

  3. 3.

    For ode23/ode23tb, \(p = 2\), whilst for ode45, \(p=4\).

  4. 4.

    Matlab ODE solver options also allow the local error to be determined using the 2-norm. By default, however, the maximum norm is used.

  5. 5.

    If you have installed Matlab’s Symbolic Math Toolbox , the following commands can be entered from the command prompt to readily evaluate this integral:

    syms t1 t h

    P = (t-t1)*(t-(t1-h))*(t-(t1-2*h))*(t-(t1-3*h));

    I4 = int(P,t,t1,t1+h);

    simplify(I4)

    where syms declares the symbolic variables t1, t and h, where t1 denotes \(t_{n-1}\). The command int symbolically evaluates the definite integral, and simplify simplifies the resulting expression to obtain the required answer.

  6. 6.

    For second-order ODE systems of the form \(\mathbf {E}\ddot{\mathbf {y}} + \mathbf {M}\dot{\mathbf {y}} + \mathbf {K}\mathbf {y} = \mathbf {F}\), \(\mathbf {E}\) is instead referred to as the mass matrix, \(\mathbf {M}\) is the damping matrix , and \(\mathbf {K}\) is the stiffness matrix .

  7. 7.

    In recent releases of Matlab, setting the mass matrix via odeset requires that function handles are used to specify the user-defined functions, rather than string expressions. Hence for this example, using options = odeset(’Mass’, ’my_mass_fun’); will not work.

  8. 8.

    Matlab and COMSOL can readily solve DAEs for which \(\frac{\partial \mathbf {g}}{\partial \mathbf {z}}\) in Eq. 3.68 is non-singular, also known as index-1 DAEs [2]. The DAE index is defined as the maximum number of system differentiations required such that for all variables \(\mathbf {y}\), \(\mathrm{d}\mathbf {y}/\mathrm{d}t\) can be uniquely determined from \(\mathbf {y}\) and t. For more information on solving index-1 DAEs using the standard Matlab ODE suite, see Shampine et al. [19].

References

  1. Anton H, Rorres C (1987) Elementary linear algebra with applications. Wiley, New York

    MATH  Google Scholar 

  2. Ascher UM, Petzold LR (1998) Computer methods for ordinary differential equations and differential-algebraic equations. SIAM, Philadelphia

    Book  MATH  Google Scholar 

  3. Beeler GW, Reuter H (1977) Reconstruction of the action potential of ventricular myocardial fibres. J Physiol 268:177–210

    Article  Google Scholar 

  4. Bogacki P, Shampine LF (1989) A 3(2) pair of Runge-Kutta formulas. Appl Math Lett 2:321–325

    Article  MathSciNet  MATH  Google Scholar 

  5. Chung J, Hulbert GM (1993) A time integration algorithm for structural dynamics with improved numerical dissipation: the generalized-alpha method. Appl Mech 60:371–375

    Article  MathSciNet  MATH  Google Scholar 

  6. Deuflhard P, Bornemann F (2002) Scientific computing with ordinary differential equations. Springer, New York

    Book  MATH  Google Scholar 

  7. Dormand JR, Prince PJ (1980) A family of embedded Runge-Kutta formulae. J Comp Appl Math 6:19–26

    Article  MathSciNet  MATH  Google Scholar 

  8. Gear CW (1973) Numerical initial value problems in ordinary differential equations. Prentice-Hall, Englewood Cliffs

    Google Scholar 

  9. Hairer E, Wanner G (1991) Solving ordinary differential equations II: stiff and differential-algebraic problems. Springer, Berlin

    Book  MATH  Google Scholar 

  10. Hairer E, Nørsett SP, Wanner G (1987) Solving ordinary differential equations I: nonstiff problems. Springer, Berlin

    Book  MATH  Google Scholar 

  11. Hosea ME, Shampine LF (1996) Analysis and implementation of TR-BDF2. Appl Num Math 20:21–37

    Article  MathSciNet  MATH  Google Scholar 

  12. Hughes TJR (1987) The finite element method: linear static and dynamic finite element analysis. Dover, New York

    MATH  Google Scholar 

  13. Izhikevich EM (2007) Dynamical systems in neuroscience: the geometry of excitability and bursting. MIT Press, Cambridge

    Google Scholar 

  14. Jansen KE, Whiting CH, Hulbert GM (2000) A generalized-\(\alpha \) method for integrating the filtered Navier-Stokes equations with a stabilized finite-element method. Comp Meth Appl Eng 190:305–319

    Article  MathSciNet  MATH  Google Scholar 

  15. Marsden JE, Tromba AJ (2003) Vector calculus, 5th edn. W H Freeman, New York

    MATH  Google Scholar 

  16. Press WH, Teukolsky SA, Vetterling WT, Flannery BP (2007) Numerical recipes: the art of scientific computing, 3rd edn. Cambridge University Press, Cambridge

    MATH  Google Scholar 

  17. Shampine LF (1994) Numerical solution of ordinary differential equations. Chapman and Hall, New York

    MATH  Google Scholar 

  18. Shampine LF, Reichelt MW (1997) The Matlab ODE suite. SIAM J Sci Comput 18:1–22

    Article  MathSciNet  MATH  Google Scholar 

  19. Shampine LF, Reichelt MW, Kierzenka JA (1999) Solving index-1 DAEs in Matlab and Simulink. SIAM Rev 41:538–552

    Article  MathSciNet  MATH  Google Scholar 

  20. Zedan H (1987) An AN-stable Rosenbrock-type method for solving stiff differential equations. Comput Math Appl 13:611–615

    Article  MathSciNet  MATH  Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to Socrates Dokos .

Problems

Problems

3.1

The Beeler–Reuter [3] model of cardiac ventricular myocyte electrical activity is given by the following system of 8 ODEs:

$$\begin{aligned} \frac{\mathrm{d}V_m}{\mathrm{d}t}= & {} -\frac{1}{C_m}\left[ i_{K_1}+i_{x_1}+i_{Na}+i_s -i_{stim}\right] \nonumber \\ \frac{\mathrm{d}\mathrm {[Ca]}_i}{\mathrm{d}t}= & {} -r_{Ca}i_s + k_{up}\left( \mathrm {[Ca]}_{SR}-\mathrm {[Ca]}_i\right) \nonumber \\ \frac{\mathrm{d}x_1}{\mathrm{d}t}= & {} \alpha _{x_1}\left( 1-x_1\right) - \beta _{x_1}x_1 \nonumber \\ \frac{\mathrm{d}m}{\mathrm{d}t}= & {} \alpha _m\left( 1-m\right) - \beta _mm \nonumber \\ \frac{\mathrm{d}h}{\mathrm{d}t}= & {} \alpha _h\left( 1-h\right) - \beta _hh \nonumber \\ \frac{\mathrm{d}j}{\mathrm{d}t}= & {} \alpha _j\left( 1-j\right) - \beta _jj \nonumber \\ \frac{\mathrm{d}d}{\mathrm{d}t}= & {} \alpha _d\left( 1-d\right) - \beta _dd \nonumber \\ \frac{\mathrm{d}f}{\mathrm{d}t}= & {} \alpha _f\left( 1-f\right) - \beta _ff \nonumber \end{aligned}$$

with four membrane ionic currents: a time-independent outward K\(^{+}\) current (\(i_{K_1}\)), a voltage-dependent outward K\(^{+}\) current (\(i_{x_1}\)), an inward Na\(^{+}\) current (\(i_{Na}\)), and a slow inward Ca\(^{2{+}}\) current (\(i_s\)), given by the expressions:

$$\begin{aligned} i_{K_1}= & {} A_{K_1}\left\{ \frac{4\left( \mathrm{e}^{0.04(V_m+85)}-1\right) }{\mathrm{e}^{0.08(V_m+53)}+\mathrm{e}^{0.04(V_m+53)}} + \frac{0.2(V_m+23)}{1-\mathrm{e}^{-0.04(V_m+23)}} \right\} \nonumber \\ i_{x_1}= & {} A_{x_1}x_1\frac{\mathrm{e}^{0.04(V_m+77)}-1}{\mathrm{e}^{0.04(V_m+35)}} \nonumber \\ i_{Na}= & {} \left( g_{Na}m^3hj+g_{NaC}\right) (V_m-V_{Na}) \nonumber \\ i_s= & {} g_sdf(V_m-V_{Ca}) \nonumber \end{aligned}$$

with

$$\begin{aligned} V_{Ca} = -82.3 - 13.0287\ln \mathrm {[Ca]}_i \nonumber \end{aligned}$$

where \(V_m\) is the transmembrane potential (in mV) and [Ca]\(_i\) denotes the free intracellular Ca\(^{2{+}}\) ion concentration (in M). The remaining variables \(x_1\), m, h, j, d, f are dimensionless kinetic gating terms whose voltage-dependent forward (\(\alpha \)) and reverse (\(\beta \)) rates (in ms\(^{-1}\)) are given by:

$$\begin{aligned} \begin{array}{ll} \alpha _{x_1} = \frac{0.0005\mathrm{e}^{0.083(V_m+50)}}{\mathrm{e}^{0.057(V_m+50)}+1}&{}\quad \beta _{x_1} = \frac{0.0013\mathrm{e}^{-0.06(V_m+20)}}{\mathrm{e}^{-0.04(V_m+20)}+1} \nonumber \\ \alpha _m = \frac{-(V_m+47)}{\mathrm{e}^{-0.1(V_m+47)}-1} &{}\quad \beta _{m} = 40\mathrm{e}^{-0.056(V_m+72)} \nonumber \\ \alpha _h = 0.126\mathrm{e}^{-0.25(V_m+77)} &{}\quad \beta _h = \frac{1.7}{\mathrm{e}^{-0.082(V_m+22.5)}+1} \nonumber \\ \alpha _j = \frac{0.055\mathrm{e}^{-0.25(V_m+78)}}{\mathrm{e}^{-0.2(V_m+78)}+1} &{}\quad \beta _j = \frac{0.3}{\mathrm{e}^{-0.1(V_m+32)}+1} \nonumber \\ \alpha _d = \frac{0.095\mathrm{e}^{-0.01(V_m-5)}}{\mathrm{e}^{-0.072(V_m-5)}+1} &{}\quad \beta _d = \frac{0.07\mathrm{e}^{-0.017(V_m+44)}}{\mathrm{e}^{0.05(V_m+44)}+1} \nonumber \\ \alpha _f = \frac{0.012\mathrm{e}^{-0.008(V_m+28)}}{\mathrm{e}^{0.15(V_m+28)}+1} &{}\quad \beta _f = \frac{0.0065\mathrm{e}^{-0.02(V_m+30)}}{\mathrm{e}^{-0.2(V_m+30)}+1} \nonumber \end{array} \end{aligned}$$

Finally, \(i_{stim}\) is the applied stimulus current given by

$$\begin{aligned} i_{stim} = \left\{ \begin{array}{ll} A_s \qquad &{} t_{on} \le t < t_{on} + t_{dur} \\ 0 &{} \mathrm {otherwise} \end{array} \right. \ \nonumber \end{aligned}$$

where \(A_s\), \(t_{on}\) and \(t_{dur}\) represent the stimulus current amplitude, onset time and duration respectively.

Initial variable values at \(t=0\) are \(V_m=-83.3\,\mathrm {mV}\), \(\mathrm {[Ca]}_i=1.87\times 10^{-7}\,\mathrm {M}\), \(x_1=0.1644\), \(m=0.01\), \(h = 0.9814\), \(j=0.9673\), \(d=0.0033\) and \(f=0.9884\), with remaining model parameters given below:

Parameter

Value

Parameter

Value

\(C_m\)

\(\upmu \)F cm\(^{-2}\)

\(g_{Na}\)

4 ms cm\({-2}\)

\(r_{Ca}\)

\(1\times 10^{-7}\) M cm\(^{2}\) nC\(^{-1}\)

\(g_{NaC}\)

0.003 ms cm\(^{-2}\)

\(\mathrm {[Ca]}_{SR}\)

\(1\times 10^{-7}\) M

\(g_s\)

0.09 ms cm\(^{-2}\)

\(k_{up}\)

0.07 ms\(^{-1}\)

\(A_s\)

40 \(\upmu \)A cm\(^{-2}\)

\(A_{K_1}\)

0.35 \(\upmu \)A cm\(^{-2}\)

\(t_{on}\)

50 ms

\(A_{x_1}\)

0.8 \(\upmu \)A cm\(^{-2}\)

\(t_{dur}\)

1 ms

\(V_{Na}\)

50 mV

  

(a) Use Matlab’s ode15s solver to solve and plot for membrane potential \(V_m\) against time from \(t=0\) to 500 ms.

(b) Write your own Matlab code to solve the same model using the forward-Euler method with a fixed step-size of 0.01 ms, plotting on the same graph \(V_m\) obtained with both the forward-Euler and ode15s methods.

(c) Verify that when the forward-Euler step-size is increased to 0.03 ms, the method becomes unstable.

(d) Now write Matlab code to solve this model using the backward-Euler method with fixed step-sizes of 0.01 and 0.1 ms, plotting these solutions with the \(V_m\) obtained using ode15s. Note that because the backward-Euler is implicit, you will need to implement Newton’s method (Eq. 3.12) to iteratively obtain the solution at each step.

(e) Finally, solve the model using Matlab’s in-built ODE solvers ode15s , ode23s , ode23t , ode23tb , ode45 , ode23 and ode113 , plotting the \(V_m\) obtained for each method on the same plot. Based on the time taken for each of these to solve the model, which solvers would you recommend for this system? HINT: use Matlab’s tic and toc timing commands to determine the computational time taken for each solver.

3.2

A minimal model of neural spiking, known as the \(I_{Na,p}+I_K\) model [13] (pronounced persistent sodium plus potassium), is defined by the ODE pair

$$\begin{aligned} \frac{\mathrm{d}V}{\mathrm{d}t}= & {} -\frac{1}{C}\left[ g_{Na}m_{\infty }(V-E_{Na}) + g_Kn(V-E_K) +g_L(V-E_L)-I\right] \nonumber \\ \frac{\mathrm{d}n}{\mathrm{d}t}= & {} \left( n_{\infty } - n\right) /{\tau _n} \nonumber \end{aligned}$$

with

$$\begin{aligned} m_{\infty } = \frac{1}{1+\exp {\left[ -\frac{V+20}{15}\right] }}, \quad n_{\infty } = \frac{1}{1+\exp {\left[ -\frac{V+25}{5}\right] }} \nonumber \end{aligned}$$

where V represents the neuronal membrane potential, n governs the kinetics of the outward K\(^{+}\) current, and I is the applied stimulus. Initial values for V and n are −72.9 mV and 0.36 respectively, with all remaining model parameters given below:

Parameter

Value

Parameter

Value

C

\(\upmu \)F cm\(^{-2}\)

\(\tau _n\)

1 ms

\(g_{Na}\)

20 ms cm\(^{-2}\)

\(g_L\)

8 ms cm\(^{-2}\)

\(E_{Na}\)

60 mV

\(E_L\)

−80 mV

\(g_K\)

10 ms cm\(^{-2}\)

I

40 \(\upmu \)A cm\(^{-2}\)

\(E_K\)

−90 mV

  

Write custom Matlab code to solve the model and plot V from \(t=0\) to 30 ms for the following two fixed-step methods:

(a) A third-order Runge–Kutta algorithm with coefficients

$$\begin{aligned} \begin{array}{l|rrr} 0 &{} &{} &{} \\ \frac{1}{2} &{} \frac{1}{2} &{} &{} \\ \frac{3}{4} &{} 0 &{} \frac{3}{4} &{} \\ \hline &{} \frac{2}{9} &{} \frac{1}{3} &{} \frac{4}{9} \\ \end{array} \nonumber \end{aligned}$$

using step-sizes of 0.01 and 0.1 ms. Plot both solutions for V on the same plot, along with the solution obtained from ode15s.

(b) The generalized-\(\alpha \) method with step size of 0.1 ms and high-frequency damping factors of 1 (no-damping), 0.5 and 0 (maximum damping). As above, plot your solutions on the same plot with the solution obtained from ode15s.

3.3

For the BDF family of implicit solvers , Newton’s method is used with an initial estimate for the solution at the next step \(y_n\) determined from the predictor of Eq. 3.60:

$$\begin{aligned} y_n^{p} = \sum _{i=0}^k \nabla ^i\,y_{n-1} \nonumber \end{aligned}$$

Verify that this predictor is equivalent to extrapolation of a polynomial of degree k passing through the previous \(k+1\) step solutions \(y_{n-1}\), \(y_{n-2}, \ldots , y_{n-k-1}\).

3.4

Determine the formula for the 7-step BDF method. For the test ODE

$$\begin{aligned} \frac{\mathrm{d}y}{\mathrm{d}t} = \lambda y \nonumber \end{aligned}$$

with \(\lambda \) real and negative, numerically estimate the absolute stability constraint on the step-size, namely step-sizes ensuring \(|y_n| < |y_{n-1}|\). Note that for this test ODE, BDF methods of orders 1-6 are absolutely stable for all step-sizes, but orders 7 and above have only limited stability and are therefore not used in practice.

Rights and permissions

Reprints and permissions

Copyright information

© 2017 Springer-Verlag Berlin Heidelberg

About this chapter

Cite this chapter

Dokos, S. (2017). Numerical Integration of Ordinary Differential Equations. In: Modelling Organs, Tissues, Cells and Devices. Lecture Notes in Bioengineering. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-642-54801-7_3

Download citation

  • DOI: https://doi.org/10.1007/978-3-642-54801-7_3

  • Published:

  • Publisher Name: Springer, Berlin, Heidelberg

  • Print ISBN: 978-3-642-54800-0

  • Online ISBN: 978-3-642-54801-7

  • eBook Packages: EngineeringEngineering (R0)

Publish with us

Policies and ethics