# Create a simple model with a pulse function
# that starts at time 5, jumps to a height of 2
# with a width of 1, and does not repeat
sfm <- stockflow() |>
update("a", "stock") |>
# Specify the global variable "times" as simulation times
update("input", "constant", eqn = "pulse(times, 5, 2, 1)") |>
update("inflow", "flow", eqn = "input(t)", to = "a")
# \dontshow{
sfm <- sim_settings(sfm, dt = .1)
# }
sim <- simulate(sfm, only_stocks = FALSE)
plot(sim)
# Create a pulse that repeats every 5 time units
sfm <- update(sfm, "input", eqn = "pulse(times, 5, 2, 1, 5)")
sim <- simulate(sfm, only_stocks = FALSE)
plot(sim)
Run the code above in your browser using DataLab