Learn R Programming

sdbuildR (version 2.0.0)

pulse: Create pulse function

Description

Create a pulse function that jumps from zero to a specified height at a specified time, and returns to zero after a specified width. The pulse can be repeated at regular intervals.

Usage

pulse(times, start, height = 1, width = 1, repeat_interval = NULL)

Value

Pulse interpolation function

Arguments

times

Vector of simulation times

start

Start time of pulse in simulation time units.

height

Height of pulse. Defaults to 1.

width

Width of pulse in simulation time units. This cannot be equal to or less than 0. To indicate an instantaneous pulse, specify the simulation step size.

repeat_interval

Interval at which to repeat pulse. Defaults to NULL to indicate no repetition.

Details

Equivalent of Pulse() in Insight Maker

See Also

step(), ramp(), seasonal()

Examples

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