| csm_run_sim | R Documentation |
Run a Cropping System Model (CSM) simulation
csm_run_sim(model_function, y_init, t, ..., method = "euler")
model_function |
a rendered model produced by
|
y_init |
a vector of initial values for the model state variables |
t |
an optional vector of time points for which simulated model outputs are desired |
... |
additional arguments to pass to model_function for simulation |
method |
numerical integration method to be used. See |
a data frame with one row for each time point specified by t
# Define state variables
lv_state <- csm_create_state(
c("x", "y"),
definition = c("prey", "predator"),
units = c("rabbits per square km", "foxes per square km"),
expression(~alpha*x-beta*x*y, ~delta*x*y-gamma*y))
# Define parameters
lv_parameters <- csm_create_parameter(
c("alpha", "beta", "gamma", "delta"),
definition = c("maximum prey per capita growth rate",
"effect of predator population on prey death rate",
"predator per capita death rate",
"effect of prey population on predator growth rate"),
units = c("rabbits per rabbit", "per fox",
"foxes per fox", "foxes per rabbit"))
# Define model
lotka_volterra_model <-
csm_create_model(
state = lv_state,
parms = lv_parameters)
# Render model into a callable R function
lotka_volterra_fun <-
csm_render_model(lotka_volterra_model,
output_type = "function",
language = "R")
# Run model simulation
lotka_volterra_out <-
csm_run_sim(model_function = lotka_volterra_fun,
y_init = c(x = 10,
y = 10),
t = csm_time_vector(0, 100, 0.01),
parms = c(alpha = 1.1,
beta = 0.4,
gamma = 0.1,
delta = 0.4))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.