# Create a simple model with a ramp function
sfm <- stockflow() |>
update("a", "stock") |>
# Specify the global variable "times" as simulation times
update("input", "constant", eqn = "ramp(times, 20, 30, 3)") |>
update("inflow", "flow", eqn = "input(t)", to = "a")
# \dontshow{
sfm <- sim_settings(sfm, save_at = 1, dt = .1)
# }
sim <- simulate(sfm, only_stocks = FALSE)
plot(sim)
# To create a decreasing ramp, set the height to a negative value
sfm <- update(sfm, "input", eqn = "ramp(times, 20, 30, -3)")
sim <- simulate(sfm, only_stocks = FALSE)
plot(sim)
Run the code above in your browser using DataLab