thk686 / odeintr

An R package for integrating differential equations in C++
18 stars 2 forks source link

Issue with get_sys_size #4

Closed fintzij closed 8 years ago

fintzij commented 8 years ago

Hello,

I am trying to incorporate the odeintr package into another package I am working on. I noticed a potentially problematic behavior in the get_sys_size function. The issue seems to be that when there are more than 10 ODEs, the function returns a system size of 10. For example, the following system clearly has twelve equations, but get_sys_size will return a value of 10:

Lorenz.sys = ' dxdt[0] = 10.0 * (x[1] - x[0]); dxdt[1] = 28.0 * x[0] - x[1] - x[0] * x[2]; dxdt[2] = -8.0 / 3.0 * x[2] + x[0] * x[1]; dxdt[3] = 10.0 * (x[1] - x[0]); dxdt[4] = 28.0 * x[0] - x[1] - x[0] * x[2]; dxdt[5] = -8.0 / 3.0 * x[2] + x[0] * x[1] dxdt[6] = 10.0 * (x[1] - x[0]); dxdt[7] = 28.0 * x[0] - x[1] - x[0] * x[2]; dxdt[8] = -8.0 / 3.0 * x[2] + x[0] * x[1] dxdt[9] = 10.0 * (x[1] - x[0]); dxdt[10] = 28.0 * x[0] - x[1] - x[0] * x[2]; dxdt[11] = -8.0 / 3.0 * x[2] + x[0] * x[1] ' odeintr:::get_sys_size(Lorenz.sys)

Thanks in advance for taking a look at this. I really appreciate the work you've put into creating this package!

--Jon

fintzij commented 8 years ago

I notice that the documentation does also point out that it is generally safer to specify the system dimension manually. Since a warning was provided, this behavior really should not be considered a bug.

Thank you again.

thk686 commented 8 years ago

The get_sys_dim function is not exported so don't rely on it. Use the "sys_dim" option to set it explicitly.

From the docs:

An attempt is made to get the length of the state vector from the system definition. If this fails, the code will likely crash your R session. It is safer to specify \code{sys_dim} directly.