A cook tests an induction hob with a pan of oil. A single one-second burst of 1 kW, at second 0, raises the oil's temperature above its starting value by h[k] °C at second k: it climbs while the heat spreads into the oil, then falls as the pan loses heat. After the last entry of h the effect of the burst has gone. That is the impulse response of pan and oil.
Now the hob is switched on at power kW at second 0 and left on. That input is a step: it is a burst of power kW at second 0, another at second 1, another at second 2, and so on. The pan is linear and time-invariant (for these modest temperatures), so the response is the sum of all those bursts' responses, each starting one second after the previous one.
Write step_response(h, power, n) that returns the temperature rise in °C at seconds 0, 1, ..., n - 1 (a list of n numbers). n can be longer than h. Press Run with plot(h, kind="stem") and plot(step_response(h, 1, 30), kind="step") to compare the two responses.
Examples
Input: h = [0.5, 2.0, 1.5, 0.5], power = 1, n = 6
Output: [0.5, 2.5, 4.0, 4.5, 4.5, 4.5]
Explanation: at second 2 the bursts of seconds 0, 1 and 2 contribute
h[2] + h[1] + h[0] = 1.5 + 2.0 + 0.5 = 4.0. From second 3 on all four entries
of h contribute, and the oil settles 4.5 °C warmer.
Input: h = [1, -1], power = 3, n = 3
Output: [3, 0, 0]
Explanation: a system that answers +1 then -1 to a burst reacts only to change:
a steady input is forgotten after one second.
Constraints
- answers are compared with a tolerance of
1e-6, so ints and floats are both fine
Goals
- See a step input as a burst at every sample, one after another
- Build the step response as the running sum of the impulse response
- Read the final value of the step response as the sum of the impulse response