[R-sig-dyn-mod] deSolve with compiled code and varying size of parms
On Thu, Mar 30, 2017 at 1:36 AM, Thomas Petzoldt <
thomas.petzoldt at tu-dresden.de> wrote:
Besides this intrinsically fixed match between the C and R vector, there are several methods that can make parameter passing more flexible, i.e. using C vectors directly instead of #define macros, or employ UNIONs between numbered vector arguments and named arguments.
Had not thought of a UNION type. For odeintr, I just compile in some globals: library(odeintr)
Lorenz.sys = '
dxdt[0] = a * (x[1] - x[0]);
dxdt[1] = b * x[0] - x[1] - x[0] * x[2];
dxdt[2] = c * x[2] + x[0] * x[1];
' # Lorenz.sys
compile_sys("lorenz", Lorenz.sys, c(a = 10, b = 28, c = -8/3)) # named
pars with defaults
x = lorenz(rep(1, 3), 100, 0.001)
par(mfrow = c(1, 2))
scatterplot3d::scatterplot3d(x[,-1], type = "l")
lorenz_set_params(b = 40) # change pars by
name
x = lorenz(rep(1, 3), 100, 0.001)
scatterplot3d::scatterplot3d(x[,-1], type = "l")
Using a struct with named state variables (x.predator, x.prey) is possible too with a bit of extra C++ coding. THK http://www.keittlab.org/