step: Create step function

View source: R/custom_func.R

stepR Documentation

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)

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

Value

Step interpolation function

See Also

ramp(), pulse(), seasonal()

Examples

# Create a simple model with a step function
# that jumps at time 50 to a height of 5
sfm <- xmile() |>
  build("a", "stock") |>
  # Specify the global variable "times" as simulation times
  build("input", "constant", eqn = "step(times, 50, 5)") |>
  build("inflow", "flow", eqn = "input(t)", to = "a")



sim <- simulate(sfm, only_stocks = FALSE)
plot(sim)

# Negative heights are also possible
sfm <- build(sfm, "input", eqn = "step(times, 50, -10)")

sim <- simulate(sfm, only_stocks = FALSE)
plot(sim)

sdbuildR documentation built on Nov. 19, 2025, 5:07 p.m.