# How to use ode\_bdf\_tol with vector parameters like in ode\_bdf?

**URL:** <https://discourse.mc-stan.org/t/how-to-use-ode-bdf-tol-with-vector-parameters-like-in-ode-bdf/29554>\
**Category:** Modeling\
**Tags:** ode\
**Created:** [November 21, 2022, 2:00pm UTC](https://discourse.mc-stan.org/t/how-to-use-ode-bdf-tol-with-vector-parameters-like-in-ode-bdf/29554 "2022-11-21T14:00:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![srossell](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/srossell/32/10567_2.png) [@srossell](https://discourse.mc-stan.org/u/srossell)\
**Post date:** [November 21, 2022, 2:00pm UTC](https://discourse.mc-stan.org/t/how-to-use-ode-bdf-tol-with-vector-parameters-like-in-ode-bdf/29554/1 "2022-11-21T14:00:31Z")

</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:

```stan
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:

```stan
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?

Best,

Sergio

---

<div class="post-metadata">

**Author:** ![WardBrian](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/wardbrian/32/12078_2.png) [@WardBrian](https://discourse.mc-stan.org/u/WardBrian)\
**Post date:** [November 21, 2022, 2:42pm UTC](https://discourse.mc-stan.org/t/how-to-use-ode-bdf-tol-with-vector-parameters-like-in-ode-bdf/29554/2 "2022-11-21T14:42:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![yizhang](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/yizhang/32/15673_2.png) [@yizhang](https://discourse.mc-stan.org/u/yizhang)\
**Post date:** [November 21, 2022, 6:51pm UTC](https://discourse.mc-stan.org/t/how-to-use-ode-bdf-tol-with-vector-parameters-like-in-ode-bdf/29554/3 "2022-11-21T18:51:29Z")

</div>

```stan
ode_bdf_tol(
      myodes,
      y0,
      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
      );

```

---

<div class="post-metadata">

**Author:** ![srossell](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/srossell/32/10567_2.png) [@srossell](https://discourse.mc-stan.org/u/srossell)\
**Post date:** [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/4 "2022-11-21T19:54:47Z")

</div>

Thanks @WardBrian

I tried:

```stan
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:

```nohighlight
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.
