Problem 159482 · medium · Level 01 Prerequisites & Setup

The Thermostat With a Slow Sensor

feedback · time delay · hysteresis · simulation · history

A thermostat is mounted in a thick plastic box, so its reading lags behind the room: it reports the temperature the room had delay minutes ago. The controller itself is the hysteresis thermostat from before; only its information is late.

The room starts at the setpoint, with the heater off. The outside is 5 °C, the room has tau = 120 minutes, and the 4 kW heater adds 0.05 * 4 = 0.2 °C per minute when on. Call the temperatures T[0] = setpoint, T[1], T[2], ... (one per minute). For each minute t = 0, 1, ..., minutes - 1:

  1. the reading is T[t - delay], or T[0] while t < delay;
  2. the thermostat decides with that reading: if off and the reading is below setpoint - band, switch on; if on and the reading is above setpoint + band, switch off;
  3. the room moves on: T[t + 1] = T[t] + (5 - T[t]) / 120 + 0.2 * h, where h is 1 with the heater on and 0 with it off.

Write delayed_thermostat(setpoint, band, delay, minutes) that returns a tuple (switches, lowest, highest): the number of times the heater switched, and the lowest and highest of T[0] to T[minutes]. Press Run with plot(temps) for a few delays to compare the swings.

Examples

Input:  setpoint = 20, band = 0.2, delay = 2, minutes = 8
Output: (1, 19.50621535, 20)
Explanation: the room cools 20, 19.875, 19.751, 19.628, 19.506, ... At minute 4 the
thermostat reads T[2] = 19.751 (below 19.8) and switches on, although the room is already
at 19.506; it then warms back up. The highest temperature is the start, 20.

Input:  setpoint = 20, band = 0.5, delay = 0, minutes = 480
Output: (40, 19.385330222, 20.558806519)

Input:  setpoint = 20, band = 0.5, delay = 10, minutes = 480
Output: (15, 18.230522303, 21.243534401)
Explanation: the same thermostat with a 10-minute delay switches less often,
but the room now swings over 3 °C instead of 1.2 °C.

Constraints

  • answers are compared with a tolerance of 1e-6; do not round

Goals

  • Simulate a controller that acts on an old measurement
  • Index into the history of a simulation to model a delay
  • See a delay in the loop turn into larger temperature swings
Starting Python…