Learn R Programming

sdbuildR (version 2.0.0)

step: Create step function

Description

Create a step function that jumps from zero to a specified height at a specified time, and remains at that height until the end of the simulation time.

Usage

step(times, start, height = 1)

Value

Step interpolation function

Arguments

times

Vector of simulation times

start

Start time of step

height

Height of step, defaults to 1

Details

Equivalent of Step() in Insight Maker

See Also

ramp(), pulse(), seasonal()

Examples

Run this code
# 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