# Create a simple model with a step function
# that jumps at time 50 to a height of 5
sfm <- stockflow() |>
update("a", "stock") |>
# Specify the global variable "times" as simulation times
update("input", "constant", eqn = "step(times, 50, 5)") |>
update("inflow", "flow", eqn = "input(t)", to = "a")
# \dontshow{
sfm <- sim_settings(sfm, dt = .1)
# }
sim <- simulate(sfm, only_stocks = FALSE)
plot(sim)
# Negative heights are also possible
sfm <- update(sfm, "input", eqn = "step(times, 50, -10)")
sim <- simulate(sfm, only_stocks = FALSE)
plot(sim)
Run the code above in your browser using DataLab