How to use ode_bdf_tol with vector parameters like in ode_bdf?

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, vector y, vector bw_t, vector bw_y, array[] real p)
        vector[N] dydt;
    return dydt;

which is integrated with ode_bdf like:

vector[N] y_sim[sim_t_dim0] = ode_bdf(myodes, y0, 0.0, sim_t, bw_t, bw_y,  p);

The above works well, no problems. But I need to specify tolerances, and would like to use ode_bdf_tol. From the documentation, I find that ode_bdf_tol does not seem to accept my parameters bw_t and bw_y, which are vectors. From the docs

Could you advice me on whether I’m doing something wrong, or if there is a workaround to my problem?



ode_bdf_tol should accept the same system functions as ode_bdf. Did you get a specific error message when you tried?

1 Like
      0.0,                              // initial time = 0
      sim_t,                            // evaluation times
      rtol, atol, max_num_steps,        // rela tolerances, absl tolerences, max steps
      bw_t, bw_y, p                     // ode params
1 Like

Thanks @WardBrian

I tried:

transformed parameters {
   vector[N] y_sim[sim_t_dim0] = ode_bdf_tol(myodes, y0, 0.0, sim_t, bw_t, bw_y, 1e-8, 1e-8, 5000, p); 

And got the following error message:

Ill-typed arguments supplied to function 'ode_bdf_tol':
(<F1>, vector, real, array[] real, vector, vector, real, real, int, array[] real)
where F1 = (real, vector, vector, vector, array[] real) => vector
Available signatures:
(<F1>, vector, real, array[] real, data real, data real, data int, vector, vector, array[] real) => vector
    The 5th argument must be real but got vector

@yizhang’s suggestion solved my issue. My script now compiles without error.