Skip to main content

Solving Ordinary Differential Equations in R

  • Chapter
  • First Online:

Part of the book series: Use R! ((USE R))

Abstract

Both Runge-Kutta and linear multistep methods are available to solve initial value problems for ordinary differential equations in the R packages deSolve and deTestSet. Nearly all of these solvers use adaptive step size control, some also control the order of the formula adaptively, or switch between different types of methods, depending on the local properties of the equations to be solved. We show how to trigger the various methods using a variety of applications pointing, where necessary, to problems that may arise. For instance, many practical applications involve discontinuities. As the integration routines assume that a solution is sufficiently differentiable over a time step, handing such discontinuities requires special consideration. We give examples of how we can implement a nonsmooth forcing term, switching behavior, and problems that include sudden jumps in the dependent variables. Since much computational efficiency can be gained by using the correct method for a particular problem, we end this chapter by providing a few guidelines as to how the most efficient solution method for a particular problem can be found.

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   49.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD   64.99
Price excludes VAT (USA)
  • Compact, lightweight 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.

    A more robust but slightly more complex method is to put parameters in a parameter vector, and pass that to the derivative function via ode’s argument parms. For models that are to be used to fit parameters to data, this is the most convenient way of passing parameters.

  2. 2.

    it is the most common mistake that beginners make.

  3. 3.

    Here it is worthwhile to point to the difference of the letter “O” and the number “0” in the definition of yini; many strange behaviors of DE models are due to mistyping O and 0.

References

  1. Arenstorf, R. F. (1963). Periodic solutions of the restricted three-body problem representing analytic continuations of Keplerian elliptic motions. American Journal of Mathematics, 85, 27–35.

    Google Scholar 

  2. Aris, R. (1965). Introduction to the analysis of chemical reactors. Englewood Cliffs: Prentice Hall.

    Google Scholar 

  3. Bogacki, P., & Shampine, L. F. (1989). A 3(2) pair of Runge–Kutta formulas. Applied Mathematics Letters, 2, 1–9.

    Google Scholar 

  4. Brown, P. N., Byrne, G. D., & Hindmarsh, A. C. (1989). VODE, a variable-coefficient ODE solver. SIAM Journal on Scientific and Statistical Computing, 10, 1038–1051.

    Google Scholar 

  5. Brugnano, L., & Magherini, C. (2004). The BiM code for the numerical solution of ODEs. Journal of Computational and Applied Mathematics, 164–165, 145–158.

    Google Scholar 

  6. Cash, J. R., & Considine, S. (1992). An MEBDF code for stiff initial value problems. ACM Transactions on Mathematical Software, 18(2), 142–158.

    Google Scholar 

  7. Cash, J. R., & Karp, A. H. (1990). A variable order Runge–Kutta method for initial value problems with rapidly varying right-hand sides. ACM Transactions on Mathematical Software, 16, 201–222.

    Google Scholar 

  8. Dormand, J. R., & Prince, P. J. (1980). A family of embedded Runge–Kutta formulae. Journal of Computational and Applied Mathematics, 6, 19–26.

    Google Scholar 

  9. Dormand, J. R., & Prince, P. J. (1981). High order embedded Runge–Kutta formulae. Journal of Computational and Applied Mathematics, 7, 67–75.

    Google Scholar 

  10. Fehlberg, E. (1967). Klassische Runge–Kutta formeln funfter and siebenter ordnung mit schrittweiten-kontrolle. Computing (Arch. Elektron. Rechnen), 4, 93–106.

    Google Scholar 

  11. Hairer, E., & Wanner, G. (1996). Solving ordinary differential equations II: Stiff and differential-algebraic problems. Heidelberg: Springer.

    Google Scholar 

  12. Hairer, E., Norsett, S. P., & Wanner, G. (2009). Solving ordinary differential equations I: Nonstiff problems (2nd rev. ed.). Heidelberg: Springer.

    Google Scholar 

  13. Hindmarsh, A. C. (1980). LSODE and LSODI, two new initial value ordinary differential equation solvers. ACM-SIGNUM Newsletter , 15, 10–11.

    Google Scholar 

  14. Hindmarsh, A. C. (1983). ODEPACK, a systematized collection of ODE solvers. In R. Stepleman (Ed.), Scientific computing: Vol. 1. IMACS transactions on scientific computation (pp. 55–64). Amsterdam: IMACS/North-Holland.

    Google Scholar 

  15. Hundsdorfer, W., & Verwer, J. G. (2003). Numerical solution of time-dependent advection-diffusion-reaction equations. Springer series in computational mathematics. Berlin: Springer.

    Google Scholar 

  16. Iavernaro, F., & Mazzia, F. (1998). Solving ordinary differential equations by generalized Adams methods: Properties and implementation techniques. Applied Numerical Mathematics, 28(2–4), 107–126. Eighth conference on the numerical treatment of differential equations (Alexisbad, 1997).

    Google Scholar 

  17. Ligges, U., & Mächler, M. (2003). Scatterplot3d–an R package for visualizing multivariate data. Journal of Statistical Software, 8(11), 1–20.

    Google Scholar 

  18. Lorenz, E. N. (1963). Deterministic non-periodic flows. Journal of Atmospheric Sciences, 20, 130–141.

    Google Scholar 

  19. Petzold, L. R. (1983). Automatic selection of methods for solving stiff and nonstiff systems of ordinary differential equations. SIAM Journal on Scientific and Statistical Computing, 4, 136–148.

    Google Scholar 

  20. Press, W. H., Teukolsky, S. A., Vetterling, W. T., & Flannery, B. P. (2007). Numerical recipes (3rd ed). Cambridge: Cambridge University Press.

    Google Scholar 

  21. Reddy, M., Yang, R. S., Andersen, M. E., & Clewell, H. J., III (2005). Physiologically based pharmacokinetic modeling: Science and applications. Hoboken: Wiley.

    Google Scholar 

  22. Robertson, H. H. (1966). The solution of a set of reaction rate equations. In J. Walsh (Ed.), Numerical analysis: An introduction (pp. 178–182). London: Academic Press.

    Google Scholar 

  23. Rossler, O. E. (1976). An equation for continous chaos. Physics Letters A, 57(5), 397–398.

    Google Scholar 

  24. Shampine, L. F. (1994). Numerical solution of ordinary differential equations. New York: Chapman and Hall.

    Google Scholar 

  25. Shampine, L. F., Gladwell, I., & Thompson, S. (2003). Solving ODEs with MATLAB. Cambridge: Cambridge University Press.

    Google Scholar 

  26. Soetaert, K., Petzoldt, T., & Setzer, R. W. (2010). Solving differential equations in R: Package deSolve. Journal of Statistical Software, 33(9), 1–25.

    Google Scholar 

  27. van Dorsselaer, J. L. M., & Spijker, M. N. (1994). The error committed by stopping the newton iteration in the numerical solution of stiff initial value problems. IMA journal of Numerical Analysis, 14, 183–209.

    Google Scholar 

  28. Verhulst, P. (1838). Notice sur la loi que la population poursuit dans son accroissement. Correspondance Mathematique et Physique, 10, 113–121.

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Rights and permissions

Reprints and permissions

Copyright information

© 2012 Springer-Verlag Berlin Heidelberg

About this chapter

Cite this chapter

Soetaert, K., Cash, J., Mazzia, F. (2012). Solving Ordinary Differential Equations in R. In: Solving Differential Equations in R. Use R!. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-642-28070-2_3

Download citation

Publish with us

Policies and ethics