Solving Partial Differential Equations in R

  • Karline Soetaert
  • Jeff Cash
  • Francesca Mazzia
Part of the Use R! book series (USE R)


R has three packages that are useful for solving partial differential equations. The R package ReacTran offers grid generation routines and the discretization of the advective-diffusive transport terms on these grids. In this way, the PDEs are either rewritten as a set of ODEs or as a set of algebraic equations. When solving the PDEs with the method of lines (MOL), the time integration can be performed using specially-designed initial value problem solvers from the R package deSolve. When all derivatives have been approximated, functions from the R package rootSolve can efficiently solve the algebraic equations. We show how to solve in R the well-known heat equation (parabolic), the wave equation (hyperbolic), Laplace’s equation (elliptic), and the advection equation. We then give some more complex examples. Most partial differential equations are defined in cartesian coordinates, but some problems are much better represented in other coordinate systems. These problems can be solved efficiently in R as well.


Model Domain ReacTran Function Advection Equation Downstream Boundary Advection Rate 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.


  1. 1.
    Burchard, H., Bolding, K., & Villarreal, M. R. (1999). GOTM, a general ocean turbulence model. Theory, applications and test cases (Tech Rep EUR 18745 EN). European Commission.Google Scholar
  2. 2.
    Hundsdorfer, W., & Verwer, J. G. (2003). Numerical solution of time-dependent advection-diffusion-reaction equations. Springer series in computational mathematics. Berlin: Springer.Google Scholar
  3. 3.
    Kachroo, P., Ozbay, K., & Hobeika, A. G. (2001). Real-time travel time estimation using macroscopic traffic flow models. In 2001 IEEE intelligent transportation systems conference proceedings, Oakland (pp. 132–137).Google Scholar
  4. 4.
    Lefever, R., Nicolis, G., & Prigogine, I. (1967). On the occurrence of oscillations around the steady state in systems of chemical reactions far from equilibrium. Journal of Chemical Physics, 47, 1045–1047.Google Scholar
  5. 5.
    Leonard, B. P. (1988). Simple high accuracy resolution programs for convective modeling of discontinuities. International Journal for Numerical Methods in Fluids, 8, 1291–1318.Google Scholar
  6. 6.
    Pearson, J. (1993). Complex patterns in a simple system. Science, 261, 189–192.Google Scholar
  7. 7.
    Roe, P. L. (1985). Some contributions to the modeling of discontinuous flows. Lectures Notes in Applied Mathematics, 22, 163–193. Amer. Math. Soc., Providence.Google Scholar
  8. 8.
    Sanz-Serna, J. M. (1984). Methods for the numerical solution of the nonlinear Schrodinger equation. Mathematics of Computation, 43, 21–27.Google Scholar
  9. 9.
    Soetaert, K. (2011). rootSolve: Nonlinear root finding, equilibrium and steady-state analysis of ordinary differential equations. R package version 1.6.2.Google Scholar
  10. 10.
    Soetaert, K., & Meysman, F. (2011). ReacTran: Reactive transport modelling in 1D, 2D and 3D. R package version 1.3.2.Google Scholar
  11. 11.
    Soetaert, K., & Meysman, F. (2012). Reactive transport in aquatic ecosystems: Rapid model prototyping in the open source software R. Environmental Modelling and Software, 32, 49–60.Google Scholar
  12. 12.
    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
  13. 13.
    Turing, A. M. (1952). The chemical basis of morphogenesis. Philosophical Transactions of the Royal Society of London Series B, 237, 37–72.Google Scholar
  14. 14.
    van Leer, B. (1979). Towards the ultimate conservative difference scheme V. A second order sequel to Godunov’s method. Journal of Computational Physics, 32, 101–136.Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2012

Authors and Affiliations

  • Karline Soetaert
    • 1
  • Jeff Cash
    • 2
  • Francesca Mazzia
    • 3
  1. 1.Department Ecosystem StudiesRoyal Netherlands Institute for Sea ResearchYersekeThe Netherlands
  2. 2.MathematicsImperial CollegeLondonUK
  3. 3.Dipartimento di MatematicaUniversity of BariBariItaly

Personalised recommendations