Questions tagged [desolve]

deSolve is an R package with functions for solving first-order ordinary differential equations ('ODE'), partial differential equations ('PDE'), differential algebraic equations ('DAE'), and delay differential equations. This tag should be used for questions regarding how to build or debug statistical models done with functions that belong to deSolve.

Package deSolve includes functions for solving initial value problems of a system of first-order ordinary differential equations (ODE), of partial differential equations (PDE), of differential algebraic equations (DAE), and of delay differential equations. The package provides an interface to the of the ODEPACK FORTRAN collection and a C-implementation of solvers of the Runge-Kutta family with fixed or variable time steps. The package also contains routines designed for solving ODEs resulting from 1-D, 2-D and 3-D partial differential equations (PDE).

Official website (r-project.org)

Repositories

Vignettes

64 questions
6
votes
3 answers

Change parameter values at time step in deSolve

I am trying to solve an ODE in R using deSolve. With the following code, I expected the parameter gamma0 takes the values 5 at time step 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 and 10, and 0 otherwise. However, the print(gamma0) shows that gamma0 stays at 0.…
Marine
  • 521
  • 1
  • 4
  • 23
5
votes
2 answers

How to solve a system of ODE with time dependent parameters in R?

I am trying to solve this system of ODEs through deSolve, dX/dt = -X*a + (Y-X)b + c and dY/dt = -Ya + (X-Y)*b for time [0,200], a=0.30, b=0.2 but c is 1 for time [50,70] and 0 otherwise. The code I have been using is, time <- seq(0, 200,…
5
votes
2 answers

ODE, multiple roots and events, R

I like to solve a system of coupled differential equations which involve multiple thresholds. Going through the R information this leads me to using ODE in combination with the root function and the event function. Going through various examples,…
Linda
  • 51
  • 2
3
votes
2 answers

Why does my deSolve model in R stop integrating when I incorporate a conditional source of mortality in my population model?

I have constructed a population model in R to identify the efficacy of potential control strategies for the cockroach population in my apartment. I have introduced a term that will add an additional source of mortality to the adult cockroach…
3
votes
1 answer

Compiled C ODE gives different results to R's using deSolve

I have an ODE which I would like to solve using compiled C code called from R's deSolve package. The ODE in question is I an exponential decay model (y'=-d* exp(g* time)*y): But running the compiled code from within R gives different results to R's…
HCAI
  • 2,213
  • 8
  • 33
  • 65
3
votes
1 answer

Error delay differential equation deSolve (dede)

I am writing a delay differential equation in deSolve (R), and I am getting an error message I am unsure how to solve. So for some background. I have a system with 12 differential equations, and 3 of those have a delay. I was successful in writing…
2
votes
1 answer

Using dede in deSolve package in RStudio to solve time-delayed ODE

I'm trying to solve this SEIRVB ODE with time delay using dede in deSolve package of R in RStudio I'm currently have this code library(deSolve) tau=0 # Parameters Lambda = 0.5 beta1 = 1.13921549 beta2 = 2.68228986 beta3 =…
Malanie
  • 23
  • 3
2
votes
1 answer

Why does the ode function in deSolve always have an event occur at time = 0?

I am writing a more complex bit of code that wasn't behaving as I expected and after some tinkering have worked out what I think is going wrong: the 'events' in the ode function of deSolve are occuring once more than I would have expected,…
2
votes
1 answer

Apply event/root function to large set of equations R deSolve

TLDR: My main challenge is just how do I write the root function that checks an arbitrary number of state variables, x, and then apply the event function such that all state variables n that have a value less than the threshold (n <= x) are acted…
colebrookson
  • 831
  • 7
  • 18
2
votes
1 answer

Replicating an ODE food-web model from a manuscript

I am trying to replicate a lake food web model published here. The model represents two food chains (littoral vs pelagic), connected by a top predator (fish). I have coded the model but when I run it after 2-3 time steps the model produces NaN. I…
flee
  • 1,253
  • 3
  • 17
  • 34
2
votes
2 answers

Computing Economic Models in R: How to apply shocks to parameter values in the euler equation?

Hi everyone im using R to try and simulate some economic models. We do this primarily through the use of the euler equation. I've figured out that applying shocks to values which are defined within the function (in this case it is k is pretty simple…
EconJohn
  • 165
  • 11
2
votes
3 answers

Parameter values as a function of another vector. deSolve

I'm looking to set up a population dynamics model where each parameter value corresponds to the temperature of that day. e.g. Simple model library(deSolve) set.seed(1) pars <- c(alpha = 1, beta = 0.2, delta = 0.5, gamma = 0.2) lv_model <-…
2
votes
1 answer

deSolve: Can't understand how to early stop ode solver with root functions

I am confused about how to stop the solver when a certain condition is met. I prepared a dummy SIR model that should stop once the I compartment reaches a certain value. But in my code the solver simply continues…
Bakaburg
  • 3,165
  • 4
  • 32
  • 64
2
votes
1 answer

in R desolve SIR model with loop and if else

I have a simple SIR model, I am trying to implement a vaccination approach (V) where at first it is checked if the infected are higher than a threshold (100), and if there are still enough susceptibles left (50) it will vaccinate a certain number…
Parinn
  • 209
  • 1
  • 7
2
votes
1 answer

Setting initial (state) values for ODE system in compiled model (deSolve, Rcpp)

I am struggling with a probably minor problem while calling compiled ODEs to be solved via the R package 'deSolve' and I seeking advice from more expert users. Background I have a couple of ODE systems to be solved with 'deSolve'. I have defined the…
RLumSK
  • 113
  • 5
1
2 3 4 5