Solving Differential Equations in R pp 157-185 | Cite as

# Solving Partial Differential Equations in R

## Abstract

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.

## Keywords

Model Domain ReacTran Function Advection Equation Downstream Boundary Advection Rate## References

- 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.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.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.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.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.Pearson, J. (1993). Complex patterns in a simple system.
*Science, 261*, 189–192.Google Scholar - 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.Sanz-Serna, J. M. (1984). Methods for the numerical solution of the nonlinear Schrodinger equation.
*Mathematics of Computation, 43*, 21–27.Google Scholar - 9.Soetaert, K. (2011).
: Nonlinear root finding, equilibrium and steady-state analysis of ordinary differential equations. R package version 1.6.2.Google Scholar**rootSolve** - 10.Soetaert, K., & Meysman, F. (2011).
: Reactive transport modelling in 1D, 2D and 3D. R package version 1.3.2.Google Scholar**ReacTran** - 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.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.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.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