Solving ODE with Exogenous Variable

I’m currently working through Bob Carpenter’s fantastic Lotka-Volterra code found here (https://mc-stan.org/users/documentation/case-studies/lotka-volterra-predator-prey.html) to solve a set of ordinary differential equations. The main parameter transformation is as follows:

      transformed parameters {

      real z[N, 2]
          = integrate_ode_rk45(dz_dt, z_init, 0, ts, theta,
            rep_array(0.0, 0), rep_array(0, 0),
            1e-6, 1e-5, 1e3);
      }

My question, in general, is whether it is possible to use the integrate_ode_rk45 function (or some other ode solver) to solve a set of differential equations that include exogenous variables? Theta is a scalar; however, I need each individual parameter (alpha, beta, gamma, and delta) to be the result of a linear model with the form: \alpha = \alpha_0 + \alpha_1*x where x is the value of the exogenous variable at each time step.

Thank you in advance for any help or insight you can provide!

Nothing wrong with that. You’d just need to make sure that your \alpha doesn’t violate any constraints. The easiest way to do that would be throw in some exps/inv_logits.

1 Like