Problem 181098 · easy · Level 01 Prerequisites & Setup

A Room on a Heater Timetable

simulation · time steps · first-order system · open loop

A storage heater in a holiday cottage runs on a fixed timetable: for every time step it is told in advance how many kilowatts to deliver. Nobody checks the temperature; that is what control engineers call open loop. You want to know what the room will actually do.

The room is a first-order system. Two things change its temperature T (°C) during a step of dt minutes:

  • heat leaks to the outside, faster the warmer the room is than the outside air T_out; the time constant tau (minutes) says how slowly: a well-insulated room has a large tau;
  • the heater adds gain °C per minute for every kilowatt it delivers.

So in each step, with the heater delivering p kW,

T = T + dt * ((T_out - T) / tau + gain * p)

(this step-by-step rule is called the Euler method: the bracket is how fast the temperature is changing right now, and dt times it is the change over one short step).

Write room_temperatures(T0, T_out, tau, gain, powers, dt) that starts at temperature T0, applies the rule once for each entry of powers in order, and returns the list of temperatures: T0 first, then the temperature after every step (so the list has len(powers) + 1 entries). Press Run with plot(room_temperatures(...), kind="step") to see the room warm up and cool down.

Examples

Input:  T0 = 12, T_out = 8, tau = 100, gain = 0.05, powers = [2, 2, 0], dt = 1
Output: [12, 12.06, 12.1194, 12.078206]
Explanation: step 1: 12 + 1 * ((8 - 12) / 100 + 0.05 * 2) = 12 + (-0.04 + 0.1) = 12.06.
Step 2 adds (8 - 12.06) / 100 + 0.1 = 0.0594. In step 3 the heater is off and the room loses 0.041194.

Input:  T0 = 20, T_out = 5, tau = 60, gain = 0.1, powers = [], dt = 2
Output: [20]

Constraints

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

Goals

  • Simulate a physical system by repeating a small update rule
  • Keep the whole history of a state, not just its last value
  • See a temperature creep towards a balance instead of jumping to it
Starting Python…