Skip to main content
v2026.11,986 entries · CC-BY 4.0

deSolve R Package: Solve ODEs in R (Install, ode(), Output)

How to use the deSolve R package for differential equations: install, ode() worked example, method choice, output columns and troubleshooting.

Written and maintained by CASRAI Editorial Board

Published

On this page

deSolve is an R package that solves initial value problems for ordinary differential equations (ODE), and also partial (PDE), differential algebraic (DAE) and delay (DDE) equations. You give it starting values, a set of time points and a function that returns the rates of change; it returns a matrix of the solution at those times. This page is for analysts and researchers who need to simulate a dynamic model in R and read the result correctly. It covers installation, a complete worked model, how to choose a method, how to read the output, and the usual failure modes.

Name check: the capitalisation matters. “deSolve” (R, numerical) is different from dsolve, the symbolic solver function in systems such as MATLAB, Maple and SymPy, and from the clothing brand that shares the spelling when typed in lower case. This page covers only the R package.

Ask CASRAI · free to tryQuestion about this guide? Ask CASRAI answers with linked sources. 2 free questions a day, no account.

Ask your first question freeSubscribe

What deSolve is used for in research

deSolve is a numerical solver: it computes an approximate trajectory of a model step by step, rather than deriving a closed-form formula. According to the package description on CRAN (version 1.42, published 2026-03-20, licensed GPL-2 | GPL-3), it provides solvers for initial value problems of ODE, PDE, DAE and DDE. It wraps established Fortran solvers (ODEPACK, DVODE/ZVODE and DASPK) plus a C implementation of Runge-Kutta methods. The authors are Karline Soetaert, Thomas Petzoldt (maintainer) and R. Woodrow Setzer.

In practice this means any research question that can be written as “how do these quantities change over time given their current values” fits: population and predator-prey dynamics, chemical and biological kinetics, compartment models in physiology and epidemiology, and ecosystem or sediment models. The package’s own reference manual includes example models of this kind, such as a Lotka-Volterra predator-prey model, a physiological model of algal growth, and a closed-chamber CCl4 metabolism model.

Because the model is an R script, the whole simulation can be versioned and re-run, which supports computational reproducibility; the package itself is open-source software.

Install and load deSolve

deSolve is distributed through CRAN, the Comprehensive R Archive Network. It depends on R 3.3.0 or later.

install.packages("deSolve")library(deSolve)

The package page on CRAN lists two vignettes: “R Package deSolve: Solving Initial Value Differential Equations in R” and “R Package deSolve: Writing Code in Compiled Languages”. The first is the general introduction; the second matters only if you move the model function into compiled C or Fortran for speed.

Step by step: solve a model with ode()

The general entry point is ode(y, times, func, parms, method = ...). The steps below use the predator-prey example from the package’s own manual page for ode.

  1. Write the model function. Its signature is function(t, y, parms, ...). It must return a list whose first element is a vector of derivatives, in the same order as the state variables in y. Any further list elements are extra outputs recorded at every time point. If y has names, those names are available inside the function.
  2. Define parameters and initial state. Name the state vector so the output columns are labelled.
  3. Define the output times. The first value of times must be the initial time.
  4. Call ode(). The default method is "lsoda".
  5. Inspect and plot. Use summary() and plot().
library(deSolve)LVmod <- function(Time, State, Pars) {  with(as.list(c(State, Pars)), {    Ingestion    <- rIng  * Prey * Predator    GrowthPrey   <- rGrow * Prey * (1 - Prey/K)    MortPredator <- rMort * Predator    dPrey        <- GrowthPrey - Ingestion    dPredator    <- Ingestion * assEff - MortPredator    return(list(c(dPrey, dPredator)))  })}pars  <- c(rIng = 0.2, rGrow = 1.0, rMort = 0.2, assEff = 0.5, K = 10)yini  <- c(Prey = 1, Predator = 2)times <- seq(0, 200, by = 1)out <- ode(yini, times, LVmod, pars)summary(out)plot(out)

Source: example 1 of the ode manual page in deSolve, with parameter comments omitted. In the manual the rates are per day, assimilation efficiency is dimensionless and K is a carrying capacity in mmol/m3; adapt units to your own system.

Choosing a method

The method argument selects the integrator. The ode manual lists: lsoda, lsode, lsodes, lsodar, vode, daspk, euler, rk4, ode23, ode45, radau, bdf, bdf_d, adams, impAdams, impAdams_d and iteration. The statements below are the manual’s.

Situation Method named in the manual
No special knowledge of the problem "lsoda", the default integrator
Stiff system of equations "bdf" (backward differentiation formula, equal to method = "lsode") or "bdf_d", described as best suited to stiff systems
Very stiff system "daspk", which the manual says may outperform "bdf"
Non-stiff system "adams", described as often the best choice for non-stiff systems
Difference equations or individual-based models "iteration": here the function returns the new state values, not rates of change

The manual also notes that the stiff-problem example uses extra arguments for the Jacobian (jactype, bandup, banddown, jacfunc); supplying a Jacobian structure is optional tuning, not a requirement.

Output and how to read it

According to the manual, ode() returns a matrix of class deSolve:

  • One row per element of times (fewer only if the integrator stopped on an unrecoverable error).
  • The first column is time.
  • Then one column per state variable, labelled with the names of y when it has names.
  • Then one column per extra value returned by func after the derivatives.

So in the example above, out[, 1] is time, out[, 2] is Prey and out[, 3] is Predator. summary(out) returns a data frame of summary statistics for each variable, and plot(out) draws each variable against time using the package’s plot method. The manual’s example also draws both curves on one set of axes with matplot(out[, 1], out[, 2:3], type = "l"). To work with the result in a tidy workflow, convert it with as.data.frame(out); see the guide to the R data frame for handling the resulting table.

Troubleshooting

  • Fewer rows than times. The manual states there is one row per time unless the integrator returns an unrecoverable error. Check the warning messages and the solver diagnostics (diagnostics(out); the manual lists a diagnostics page for printing solver characteristics).
  • Wrong or swapped results. The derivatives must be returned in the same order as the state variables in y. Returning c(dPredator, dPrey) for a state of c(Prey, Predator) runs without error and gives the wrong model.
  • Error about the return value. func must return a list, with the derivative vector as its first element: list(c(dx, dy)), not a bare vector.
  • Very slow or failing runs on a stiff model. Switch from the default to "bdf", "bdf_d" or "daspk" as in the method table.
  • Time-varying inputs (forcing). The manual’s second example passes an interpolating function (built with approxfun) as an extra argument to the model function; the package also has documentation pages on forcings and on events and roots.

Free alternatives in other languages

If your project is not in R, these are documented equivalents. The table reports only what each project’s own documentation states (read 2026-11-07).

Tool Language Entry point and methods stated in its documentation
deSolve R ode(); default lsoda; stiff options bdf, bdf_d, daspk, radau
SciPy scipy.integrate.solve_ivp Python solve_ivp(fun, t_span, y0, method='RK45', ...); methods RK45, RK23, DOP853, Radau, BDF, LSODA; the documentation points to Radau and BDF for stiff problems; result has t and y arrays
DifferentialEquations.jl Julia, with Python (diffeqpy) and R (diffeqr) interfaces Suite covering ODE, SDE, DAE and DDE; its documentation says the R interface is on CRAN and covers only a subset of the package

A notable difference when moving between them: SciPy returns y with one row per state variable and one column per time point, whereas deSolve returns time in the first column and one row per time point. If you are coming from MATLAB, see ode45 in MATLAB and the MATLAB equation solver guide; deSolve exposes an "ode45" method name too.

FAQ

What is dsolve?

dsolve is a different tool: the name of a symbolic differential-equation solver function in other systems (for example in MATLAB, Maple and SymPy). It tries to produce a formula. deSolve, by contrast, is an R package that computes numerical solutions at chosen time points.

Is deSolve only for ordinary differential equations?

No. The CRAN description lists ODE, PDE, DAE and DDE solvers. Dedicated functions include dede for delay equations, daspk for differential algebraic equations, and ode.1D, ode.2D and ode.3D for models discretised in one to three spatial dimensions.

Which method should I start with?

Start with the default, lsoda, and change only if the diagnostics or run time suggest the system is stiff; see the method table above.

Does the package cover the clothing brand, “d-1” or AI solvers that the same searches return?

No. Those are unrelated to the R package, and this page does not address them.

Sources

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about deSolve R Package: Solve ODEs in R (Install, ode(), Output)

2 free questions a day, no account.

An AI assistant for research: funder rules, compliance, methods and publishing. It links the sources behind its answers and labels answers that come from a web search.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays open to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →