Learn R Programming

sdbuildR (version 2.0.0)

ramp: Create ramp function

Description

Create a ramp function that increases linearly from 0 to a specified height at a specified start time, and stays at this height after the specified end time.

Usage

ramp(times, start, finish, height = 1)

Value

Ramp interpolation function

Arguments

times

Vector of simulation times

start

Start time of ramp

finish

End time of ramp

height

End height of ramp, defaults to 1

Details

Equivalent of Ramp() in Insight Maker

See Also

step(), pulse(), seasonal()

Examples

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