## Not run: ------------------------------------
# # Lorenz model from odeint examples
# pars = c(sigma = 10, R = 28, b = 8 / 3)
# Lorenz.sys = '
# dxdt[0] = sigma * (x[1] - x[0]);
# dxdt[1] = R * x[0] - x[1] - x[0] * x[2];
# dxdt[2] = -b * x[2] + x[0] * x[1];
# ' # Lorenz.sys
# cat(JacobianCpp(Lorenz.sys))
# compile_implicit("lorenz", Lorenz.sys, pars, TRUE)
# x = lorenz(rep(1, 3), 100, 0.001)
# plot(x[, c(2, 4)], type = 'l', col = "steelblue")
# Sys.sleep(0.5)
# # Stiff example from odeint docs
# Stiff.sys = '
# dxdt[0] = -101.0 * x[0] - 100.0 * x[1];
# dxdt[1] = x[0];
# ' # Stiff.sys
# cat(JacobianCpp(Stiff.sys))
# compile_implicit("stiff", Stiff.sys)
# x = stiff(c(2, 1), 7, 0.001)
# plot(x[, 1:2], type = "l", lwd = 2, col = "steelblue")
# lines(x[, c(1, 3)], lwd = 2, col = "darkred")
# # Robertson chemical kinetics problem
# Robertson = '
# dxdt[0] = -alpha * x[0] + beta * x[1] * x[2];
# dxdt[1] = alpha * x[0] - beta * x[1] * x[2] - gamma * x[1] * x[1];
# dxdt[2] = gamma * x[1] * x[1];
# ' # Robertson
# pars = c(alpha = 0.04, beta = 1e4, gamma = 3e7)
# init.cond = c(1, 0, 0)
# cat(JacobianCpp(Robertson))
# compile_implicit("robertson", Robertson, pars, TRUE)
# at = 10 ^ seq(-5, 5, len = 400)
# x = robertson_at(init.cond, at)
# par(mfrow = c(3, 1), mar = rep(0.5, 4), oma = rep(5, 4), xpd = NA)
# plot(x[, 1:2], type = "l", lwd = 3,
# col = "steelblue", log = "x", axes = F, xlab = NA)
# axis(2); box()
# plot(x[, c(1, 3)], type = "l", lwd = 3,
# col = "steelblue", log = "x", axes = F, xlab = NA)
# axis(4); box()
# plot(x[, c(1, 4)], type = "l", lwd = 3,
# col = "steelblue", log = "x", axes = F)
# axis(2); axis(1); box()
## ---------------------------------------------
Run the code above in your browser using DataLab