Using ode_rk45_tol without knowing the output size

Hello,

For my model, I have to use an ode solver. However I have two questions for the ode_rk45_tol function available in stan.

First, the documentation of this function is: 'ode_rk45_tol(function ode, vector initial_state, real initial_time, array real times, data real rel_tol, data real abs_tol, int max_num_steps, …)`; my question is, if I want to add more arguments to be inputted into the ‘function ode’, the documentation states that any extra arguments are represented as ‘…’ at the end. Does this mean any variables added after the max_num_steps will be treated as extra or is there something that needs to be done in order to declare them as extra variables?

Second, when the ode solver runs, how do I know the size of its matrix output? Since it is forced that I declare the matrix size beforehand, I am not sure how I would go about setting the size. My current idea is to run the ode solver multiple times and just taking size() of it to determine the seize, but that is very inefficient and I would love to hear of any other methods. Perhaps there is a way to calculate its output size?

edit: I would also appreciate if anyone knows what the ode solver would output in the event that it runs into an error (like a given parameter would not allow for the ode solver to complete its functions). I am trying to emulate the try/except method from python, but since try isn’t an option in stan, I am thinking of doing an “if (failed ode output)” kind of thing. Thanks!

Thank you in advance for any input!

The number of outputs is determined by the number of time-points requested. Maybe have a read of the intro here:

https://mc-stan.org/users/documentation/case-studies/convert_odes.html

Thank you, that was a complete misunderstanding on my part. I was referring older code which had a preset value without explanation.