Problem 548842 · easy · Level 05 Advanced Algorithms & Graphs

A Hot Plate Sampled Too Slowly

sampling period · zero-order hold · discretisation · stability · first-order system

A laboratory hot plate is a first-order system: its temperature above the room, y in °C, obeys

tau * (rate of change of y) = -y + gain * u

with u the heater power in per cent and tau the time constant in seconds. A small computer reads y every Ts seconds, computes u = K * (r - y) and holds that power until the next reading (a zero-order hold). Because u is constant over one period, the exact solution over that period gives a difference equation with no Euler error at all:

y[k+1] = a * y[k] + b * u[k],    a = exp(-Ts / tau),    b = gain * (1 - a)

(a is how much of the old temperature is left after one period; b is how far a constant power pushes it in that time.) With u[k] = K * (r - y[k]) the loop is y[k+1] = (a - b*K) * y[k] + b*K * r: one closed-loop pole at p = a - b*K, stable when |p| < 1.

The continuous loop is stable for every gain, but the sampled one is not: if the computer waits too long, the power it set for a temperature that is long gone overshoots, and the next reading overcorrects the other way. Solving a - b*K > -1 for Ts gives the longest stable period

Ts_max = tau * ln((gain*K + 1) / (gain*K - 1))     when gain*K > 1

and no limit at all (None) when gain*K <= 1.

Write sampled_heater(tau, gain, K, periods) that returns a pair: the list of closed-loop poles p, one for each sampling period in periods (in the same order), and Ts_max. Press Run with plot(periods, poles, kind="scatter") to see the pole slide from near 1 down through 0 and out past -1.

Examples

Input:  tau = 100, gain = 2, K = 5, periods = [1, 10, 25]
Output: ([0.8905481712408492, -0.04678840160444531, -1.433191386214546], 20.067069546215123)
Explanation: sampled every second the pole is 0.89, a smooth approach; every 10 s it is near 0 (the
heater nearly closes the gap in one step); every 25 s it is -1.43: each reading overcorrects the
last one by more, and the temperature swings wider and wider. The limit is 20.07 s.

Input:  tau = 30, gain = 0.4, K = 2, periods = [1, 5, 60]
Output: ([0.9409889808676106, 0.7236671048031054, -0.5563964901740972], None)
Explanation: gain*K = 0.8 is too gentle ever to overcorrect past -1.

Constraints

  • answers are compared with a tolerance of 1e-6; a list is accepted in place of the pair

Goals

  • Discretise a first-order plant exactly for an input held constant between samples
  • Find the closed-loop pole of a sampled proportional loop
  • Work out the longest sampling period before the loop goes unstable
Starting Python…