# \#ode

**URL:** https://discourse.mc-stan.org/tag/ode/59.md

[Latest](https://discourse.mc-stan.org/latest.md) · [Categories](https://discourse.mc-stan.org/categories.md) · [Tags](https://discourse.mc-stan.org/tags.md)

---

## [Vector-valued functions with manual gradients in external C++](https://discourse.mc-stan.org/t/vector-valued-functions-with-manual-gradients-in-external-c/32297)

<div class="topic-metadata">

**Author:** [@alphillips](https://discourse.mc-stan.org/u/alphillips)\
**Replies:** 20\
**Last updated:** [June 15, 2026, 7:36am UTC](https://discourse.mc-stan.org/t/vector-valued-functions-with-manual-gradients-in-external-c/32297 "2026-06-15T07:36:11Z")

</div>

Hi, I’m trying to develop an ODE model which will eventually use values from an external C++ library to inform the derivatives (and gradients of this function). Hence, I’ve started by writing a very simple ODE model wit…

---

## [Parameter Inference for Epidemiological ODE Models](https://discourse.mc-stan.org/t/parameter-inference-for-epidemiological-ode-models/39760)

<div class="topic-metadata">

**Author:** [@blakeacorrigan](https://discourse.mc-stan.org/u/blakeacorrigan)\
**Replies:** 2\
**Last updated:** [June 25, 2025, 1:55pm UTC](https://discourse.mc-stan.org/t/parameter-inference-for-epidemiological-ode-models/39760 "2025-06-25T13:55:37Z")

</div>

I have a deterministic ODE model that I want to fit to time series data. I’m interested in performing parameter inference using Stan, but without relying on the usual likelihood-based methods. Are there any tutorials or …

---

## [Speeding a bioenergetic ODE model](https://discourse.mc-stan.org/t/speeding-a-bioenergetic-ode-model/23051)

<div class="topic-metadata">

**Author:** [@palmer](https://discourse.mc-stan.org/u/palmer)\
**Replies:** 28\
**Last updated:** [September 23, 2024, 11:27am UTC](https://discourse.mc-stan.org/t/speeding-a-bioenergetic-ode-model/23051 "2024-09-23T11:27:57Z")

</div>

Dear all, After a hard time, I have implemented in STAN a bioenergetic model for the size and energy dynamics of an animal (a fish in our case). The model (dynamic energy budged model, or DEB) has theoretical support (D…

---

## [Setting ODE integrator time step to be different than t](https://discourse.mc-stan.org/t/setting-ode-integrator-time-step-to-be-different-than-t/36450)

<div class="topic-metadata">

**Author:** [@morg\_ana](https://discourse.mc-stan.org/u/morg_ana)\
**Replies:** 6\
**Last updated:** [September 12, 2024, 11:37am UTC](https://discourse.mc-stan.org/t/setting-ode-integrator-time-step-to-be-different-than-t/36450 "2024-09-12T11:37:02Z")

</div>

Hi everyone, I’m quite new to modeling and Stan, so this might be a stupid question, but I’m still on a learning curve! I’m trying to model transmission of an infectious disease with yearly rates defining the flow betw…

---

## [Updating ode to new syntax. Exception: ode\_rk45: ode paramers and data is inf](https://discourse.mc-stan.org/t/updating-ode-to-new-syntax-exception-ode-rk45-ode-paramers-and-data-is-inf/35900)

<div class="topic-metadata">

**Author:** [@BjarkeHautop](https://discourse.mc-stan.org/u/BjarkeHautop)\
**Replies:** 1\
**Last updated:** [July 17, 2024, 8:09pm UTC](https://discourse.mc-stan.org/t/updating-ode-to-new-syntax-exception-ode-rk45-ode-paramers-and-data-is-inf/35900 "2024-07-17T20:09:06Z")

</div>

I’m trying to update some ode Stan code. My updated Stan code looks like this functions { vector sir(real t, vector y, real beta, real gamma, array\[\] int x\_i) { real S = y\[1\]; real I = y\[2\]; real R = y\[3\];…

---

## [Multivariate ODE initialization issues](https://discourse.mc-stan.org/t/multivariate-ode-initialization-issues/34219)

<div class="topic-metadata">

**Author:** [@jimjunker1](https://discourse.mc-stan.org/u/jimjunker1)\
**Replies:** 5\
**Last updated:** [March 27, 2024, 8:00pm UTC](https://discourse.mc-stan.org/t/multivariate-ode-initialization-issues/34219 "2024-03-27T20:00:36Z")

</div>

I am new to coding models directly in STAN and this also happens to be my first attempt at fitting an ODE model using it. I am having a few issues with the model initialization and have not been able to gather from the f…

---

## [Error "Stan model 'anon\_model' does not contain samples"](https://discourse.mc-stan.org/t/error-stan-model-anon-model-does-not-contain-samples/34276)

<div class="topic-metadata">

**Author:** [@morg\_ana](https://discourse.mc-stan.org/u/morg_ana)\
**Replies:** 2\
**Last updated:** [March 12, 2024, 3:30pm UTC](https://discourse.mc-stan.org/t/error-stan-model-anon-model-does-not-contain-samples/34276 "2024-03-12T15:30:01Z")

</div>

Chains do not contain any samples Hi everyone, I am new to mathematical modelling as well as Rstan and I’m trying to fit my first, pretty simplistic, compartmental model (for disease transmission using ODEs) the model…

---

## [How to add autocorrelation of observation errors?](https://discourse.mc-stan.org/t/how-to-add-autocorrelation-of-observation-errors/33921)

<div class="topic-metadata">

**Author:** [@jakediamond](https://discourse.mc-stan.org/u/jakediamond)\
**Replies:** 5\
**Last updated:** [March 4, 2024, 8:17am UTC](https://discourse.mc-stan.org/t/how-to-add-autocorrelation-of-observation-errors/33921 "2024-03-04T08:17:10Z")

</div>

Hi all, I have a two observed time series (Y1 and Y2) that I am trying to fit an ODE model to. The time series are at an hourly time step over multiple days. I use the Euler method to get the estimated values (Y1\_hat an…

---

## [Learning large ODE systems from data](https://discourse.mc-stan.org/t/learning-large-ode-systems-from-data/33557)

<div class="topic-metadata">

**Author:** [@ystad](https://discourse.mc-stan.org/u/ystad)\
**Replies:** 0\
**Last updated:** [December 12, 2023, 1:48am UTC](https://discourse.mc-stan.org/t/learning-large-ode-systems-from-data/33557 "2023-12-12T01:48:55Z")

</div>

In the recent years, Sparse Identification of Nonlinear Dynamical systems (SINDy) has become quite popular to learn ODE systems (ODEs) from data. SINDy is basically regularized regression on ODEs coefficients. The PySIND…

---

## [Speeding up an ODE model](https://discourse.mc-stan.org/t/speeding-up-an-ode-model/32514)

<div class="topic-metadata">

**Author:** [@sha](https://discourse.mc-stan.org/u/sha)\
**Replies:** 1\
**Last updated:** [August 30, 2023, 7:04am UTC](https://discourse.mc-stan.org/t/speeding-up-an-ode-model/32514 "2023-08-30T07:04:45Z")

</div>

Could someone please help me to speed up this code? It is extremely slow even for a single chain. functions{ vector PK3cmt(real t, vector states, vector theta){ real ka = theta\[1\]; real CL = theta\[2\]; real…

---

## [Ode\_rk45 solving for only one time point](https://discourse.mc-stan.org/t/ode-rk45-solving-for-only-one-time-point/32436)

<div class="topic-metadata">

**Author:** [@sha](https://discourse.mc-stan.org/u/sha)\
**Replies:** 2\
**Last updated:** [August 15, 2023, 1:47pm UTC](https://discourse.mc-stan.org/t/ode-rk45-solving-for-only-one-time-point/32436 "2023-08-15T13:47:42Z")

</div>

Dear all, I am trying to solve an ODE at one time point T1 in future hence I feed a single value of solution time to the integrator by: real T1 = times\[i\]; however I got data type error: Semantic error in ‘string’, l…

---

## [Parameter estimation for seasonal SEIR model with time-varying transmission rates](https://discourse.mc-stan.org/t/parameter-estimation-for-seasonal-seir-model-with-time-varying-transmission-rates/32064)

<div class="topic-metadata">

**Author:** [@Amanda1](https://discourse.mc-stan.org/u/Amanda1)\
**Replies:** 2\
**Last updated:** [August 2, 2023, 8:01pm UTC](https://discourse.mc-stan.org/t/parameter-estimation-for-seasonal-seir-model-with-time-varying-transmission-rates/32064 "2023-08-02T20:01:50Z")

</div>

Dear all, I’m new to Stan and I’m currently following the tutorial on “Bayesian workflow for disease transmission modeling in Stan” to develop an SEIR model for the transmission of hand, foot, and mouth disease (HFMD). …

---

## [Restrict one output of ODE to peak within a specific time range?](https://discourse.mc-stan.org/t/restrict-one-output-of-ode-to-peak-within-a-specific-time-range/30487)

<div class="topic-metadata">

**Author:** [@mtan9](https://discourse.mc-stan.org/u/mtan9)\
**Replies:** 2\
**Last updated:** [May 17, 2023, 9:11am UTC](https://discourse.mc-stan.org/t/restrict-one-output-of-ode-to-peak-within-a-specific-time-range/30487 "2023-05-17T09:11:46Z")

</div>

Hi all, I’ve been trying to run an ODE model on Stan, but have been facing issues with the fit. I know that the y\[3\] output from the ode solver should have a peak within a certain time period. But because the data I ha…

---

## [Possible bug in expose\_functions(..) with new ODE interface](https://discourse.mc-stan.org/t/possible-bug-in-expose-functions-with-new-ode-interface/30425)

<div class="topic-metadata">

**Author:** [@AlexP](https://discourse.mc-stan.org/u/AlexP)\
**Replies:** 1\
**Last updated:** [March 31, 2023, 7:32am UTC](https://discourse.mc-stan.org/t/possible-bug-in-expose-functions-with-new-ode-interface/30425 "2023-03-31T07:32:01Z")

</div>

I’m simulating a system of differential equations (ODEs). Initially I used integrate\_ode\_rk45 as tutorials suggested. I then save obtained posterior and do a simulation for new conditions. According to the deprecation e…

---

## ["Expected non-array type after "array" declaration" error in ODE solver of Cmdstanr with missing data](https://discourse.mc-stan.org/t/expected-non-array-type-after-array-declaration-error-in-ode-solver-of-cmdstanr-with-missing-data/30339)

<div class="topic-metadata">

**Author:** [@geraltofrivia](https://discourse.mc-stan.org/u/geraltofrivia)\
**Replies:** 4\
**Last updated:** [February 10, 2023, 9:07am UTC](https://discourse.mc-stan.org/t/expected-non-array-type-after-array-declaration-error-in-ode-solver-of-cmdstanr-with-missing-data/30339 "2023-02-10T09:07:52Z")

</div>

I am trying to run a Measurement error model using CmdStan’s ode\_rk45 solver. The data set has T rows and 3 columns, only the first column’s data is available. But the initial condition is available for all 3 columns (th…

---

## [Ode\_rk45 signature](https://discourse.mc-stan.org/t/ode-rk45-signature/19399)

<div class="topic-metadata">

**Author:** [@zenkavi](https://discourse.mc-stan.org/u/zenkavi)\
**Replies:** 15\
**Last updated:** [January 16, 2023, 3:58am UTC](https://discourse.mc-stan.org/t/ode-rk45-signature/19399 "2023-01-16T03:58:42Z")

</div>

Hi, I’m trying to model activity propagation in a network with N nodes for N\_TS time points that spreads as described by the following evolution equation: \\frac{dx\_i}{dt}\\tau\_i = -x\_i(t) + s\\phi\\big(x\_i(t)\\big) + g\\Big…

---

## [Signal imputation in ODE's](https://discourse.mc-stan.org/t/signal-imputation-in-odes/29701)

<div class="topic-metadata">

**Author:** [@robshavr](https://discourse.mc-stan.org/u/robshavr)\
**Replies:** 3\
**Last updated:** [December 8, 2022, 9:10pm UTC](https://discourse.mc-stan.org/t/signal-imputation-in-odes/29701 "2022-12-08T21:10:35Z")

</div>

Dear Stan-Community, I am working on my first ODE translation from R (using package deSolve) to Stan as a Stan newbie. So, far, the model works with a constant input, but generally I want to input a signal as a time-ser…

---

## [How to use ode\_bdf\_tol with vector parameters like in ode\_bdf?](https://discourse.mc-stan.org/t/how-to-use-ode-bdf-tol-with-vector-parameters-like-in-ode-bdf/29554)

<div class="topic-metadata">

**Author:** [@srossell](https://discourse.mc-stan.org/u/srossell)\
**Replies:** 3\
**Last updated:** [November 21, 2022, 7:54pm UTC](https://discourse.mc-stan.org/t/how-to-use-ode-bdf-tol-with-vector-parameters-like-in-ode-bdf/29554 "2022-11-21T19:54:47Z")

</div>

Hi all, I’ve been using Stan for ODEs for some time now, many thanks. With the newer way of writing and solving ODEs I stumbled into the following difficulty: I need to specify ode functions like: vector myodes(real t,…

---

## [Rounding issues in ODE-solver](https://discourse.mc-stan.org/t/rounding-issues-in-ode-solver/29477)

<div class="topic-metadata">

**Author:** [@JudithBouman2412](https://discourse.mc-stan.org/u/JudithBouman2412)\
**Replies:** 12\
**Last updated:** [November 18, 2022, 7:42am UTC](https://discourse.mc-stan.org/t/rounding-issues-in-ode-solver/29477 "2022-11-18T07:42:13Z")

</div>

Dear Stan-community, I am modelling a simple SEIR model in stan. \\frac{dS}{dt} = - \\beta S I \\\\ \\frac{dE}{dt} = \\beta S I - \\tau E \\\\ \\frac{dI}{dt} = \\tau E - \\gamma I \\\\ \\frac{dR}{dt} = \\gamma I Due to l…

---

## [Separating the outputs of ODE solver](https://discourse.mc-stan.org/t/separating-the-outputs-of-ode-solver/29392)

<div class="topic-metadata">

**Author:** [@geraltofrivia](https://discourse.mc-stan.org/u/geraltofrivia)\
**Replies:** 6\
**Last updated:** [November 10, 2022, 5:08pm UTC](https://discourse.mc-stan.org/t/separating-the-outputs-of-ode-solver/29392 "2022-11-10T17:08:51Z")

</div>

functions { vector test(real t, vector y, real alpha, real eta, real lambda, real beta) { vector\[2\] dydt; dydt\[1\] = alpha \* y\[2\]; dydt\[2\] = e…

---

## [The Monster Model | Hierarchical ODE models](https://discourse.mc-stan.org/t/the-monster-model-hierarchical-ode-models/22683)

<div class="topic-metadata">

**Author:** [@Funko\_Unko](https://discourse.mc-stan.org/u/Funko_Unko)\
**Replies:** 17\
**Last updated:** [November 9, 2022, 7:54am UTC](https://discourse.mc-stan.org/t/the-monster-model-hierarchical-ode-models/22683 "2022-11-09T07:54:29Z")

</div>

So I was actually looking around for something else (scalability/massive parallelism) when I stumbled across this thread: Scalable Bayesian multilevel modeling - #31 by andrewgelman As I understood the model/paper it d…

---

## [ODE solver errors & model parameterisations](https://discourse.mc-stan.org/t/ode-solver-errors-model-parameterisations/26725)

<div class="topic-metadata">

**Author:** [@bernadette-eu](https://discourse.mc-stan.org/u/bernadette-eu)\
**Replies:** 3\
**Last updated:** [March 14, 2022, 9:53am UTC](https://discourse.mc-stan.org/t/ode-solver-errors-model-parameterisations/26725 "2022-03-14T09:53:38Z")

</div>

Hello, I am working on an age-structured Bayesian SEIR transmission model, fitted to daily mortality/incidence counts. The benchmark is a SEIR model without age structure, yielding the estimated posterior number of new…

---

## [Error when solving ODE in transformed parameters block but not in model block](https://discourse.mc-stan.org/t/error-when-solving-ode-in-transformed-parameters-block-but-not-in-model-block/26521)

<div class="topic-metadata">

**Author:** [@tga99](https://discourse.mc-stan.org/u/tga99)\
**Replies:** 4\
**Last updated:** [February 27, 2022, 3:35pm UTC](https://discourse.mc-stan.org/t/error-when-solving-ode-in-transformed-parameters-block-but-not-in-model-block/26521 "2022-02-27T15:35:43Z")

</div>

I have been trying to fit a model using CmdStanR that involves solving an ODE in order to find a posterior for its parameters. My model currently solves this ODE in the model block and runs fine. I would like it to solve…

---

## [Stan differential equation functionality development priorities](https://discourse.mc-stan.org/t/stan-differential-equation-functionality-development-priorities/14906)

<div class="topic-metadata">

**Author:** [@xiehw](https://discourse.mc-stan.org/u/xiehw)\
**Replies:** 74\
**Last updated:** [December 11, 2020, 6:41pm UTC](https://discourse.mc-stan.org/t/stan-differential-equation-functionality-development-priorities/14906 "2020-12-11T18:41:04Z")

</div>

Tagging @charlesm93, @wds15, @yizhang, and @bbbales2 to start for this question, since I know you guys are working on various things related to the topic. I was wondering about the general state of priorities right now …

---

## [Issues getting non-linear ODE model inference going, starting off with \`ode\_ckrk\` function error message](https://discourse.mc-stan.org/t/issues-getting-non-linear-ode-model-inference-going-starting-off-with-ode-ckrk-function-error-message/25787)

<div class="topic-metadata">

**Author:** [@xiehw](https://discourse.mc-stan.org/u/xiehw)\
**Replies:** 4\
**Last updated:** [December 23, 2021, 11:20pm UTC](https://discourse.mc-stan.org/t/issues-getting-non-linear-ode-model-inference-going-starting-off-with-ode-ckrk-function-error-message/25787 "2021-12-23T23:20:07Z")

</div>

Hi, Transitioning from this previous thread, where I asked about arranging data types and dimensions to facilitate inference conditional on multidimensional ODE states, as I’m now looking to resolve model issues. My ens…

---

## [Fitting parameters of a simple process model (optimisation & uncertainty)](https://discourse.mc-stan.org/t/fitting-parameters-of-a-simple-process-model-optimisation-uncertainty/16349)

<div class="topic-metadata">

**Author:** [@tommylees112](https://discourse.mc-stan.org/u/tommylees112)\
**Replies:** 13\
**Last updated:** [December 21, 2021, 8:35pm UTC](https://discourse.mc-stan.org/t/fitting-parameters-of-a-simple-process-model-optimisation-uncertainty/16349 "2021-12-21T20:35:42Z")

</div>

I have a very simple hydrological model. The model can be simply conceptualised as below: I am trying to learn the values of the parameters a, b and c. Where: P = Precipitation Inputs L = Losses S = Storage (ground…

---

## [How can I reparametrize an ODE-based filter to improve efficiency (especially treedepth)?](https://discourse.mc-stan.org/t/how-can-i-reparametrize-an-ode-based-filter-to-improve-efficiency-especially-treedepth/25099)

<div class="topic-metadata">

**Author:** [@frnkcg](https://discourse.mc-stan.org/u/frnkcg)\
**Replies:** 10\
**Last updated:** [December 6, 2021, 7:16pm UTC](https://discourse.mc-stan.org/t/how-can-i-reparametrize-an-ode-based-filter-to-improve-efficiency-especially-treedepth/25099 "2021-12-06T19:16:33Z")

</div>

I have noisy measurements of acceleration and position and want to obtain corrected values for acceleration, velocity, and position. To do this I express acceleration using splines, and integrate it in time to obtain vel…

---

## [ODE model with Boolean control variable](https://discourse.mc-stan.org/t/ode-model-with-boolean-control-variable/24958)

<div class="topic-metadata">

**Author:** [@mmorenozam](https://discourse.mc-stan.org/u/mmorenozam)\
**Replies:** 7\
**Last updated:** [November 10, 2021, 5:45pm UTC](https://discourse.mc-stan.org/t/ode-model-with-boolean-control-variable/24958 "2021-11-10T17:45:10Z")

</div>

Hello! I am trying to reproduce a published ODE model of methane production ​by cows. The model is quite simple: \\frac{dy}{dt}=c\\,u-d\\,y where u is a Boolean control variable that takes values of 1 when the cow is fed,…

---

## [Adjoint ODE behaviour](https://discourse.mc-stan.org/t/adjoint-ode-behaviour/24703)

<div class="topic-metadata">

**Author:** [@bernadette-eu](https://discourse.mc-stan.org/u/bernadette-eu)\
**Replies:** 56\
**Last updated:** [November 10, 2021, 12:52pm UTC](https://discourse.mc-stan.org/t/adjoint-ode-behaviour/24703 "2021-11-10T12:52:31Z")

</div>

Hello everyone, Our work is currently involved with a Bayesian SIR model with a time-varying infection rate on daily COVID-19 mortality data. The SIR ODE function keeps information about the three compartments (S,I,R) a…

---

## [CoDatMo Liverpool & UNINOVE models (slow ODE implementation and Trapezoidal Solver)](https://discourse.mc-stan.org/t/codatmo-liverpool-uninove-models-slow-ode-implementation-and-trapezoidal-solver/22500)

<div class="topic-metadata">

**Author:** [@storopoli](https://discourse.mc-stan.org/u/storopoli)\
**Replies:** 94\
**Last updated:** [November 9, 2021, 9:10am UTC](https://discourse.mc-stan.org/t/codatmo-liverpool-uninove-models-slow-ode-implementation-and-trapezoidal-solver/22500 "2021-11-09T09:10:56Z")

</div>

Hey guys! I was discussing a possible trapezoidal ODE solver implementation in Stan with @wds15, @Bob\_Carpenter, @bbbales2 and @charlesm93 and the discussion took a detour to “what are you doing that you need a trapezoid…

[Next page](https://discourse.mc-stan.org/tag/ode/59.md?match_all_tags=true&page=1&tags%5B%5D=ode)
