Exercises
Exercise 1: Temperature control of a nuclear reactor using two rods (≈45 min)
Goal: practice formulating a hybrid automaton (identifying its components) and simulating it.
Part A (pen and paper)
Temperature inside a nuclear reactor is controlled by inserting or withdrawing control rods. Two rods are available; only one can be inserted at a time. Upon insertion of a rod, the temperature decreases; without any rod inserted the temperature rises. Namely, the temperature (in °C) without any rod inserted evolves according to \dot T(t) = 0.1 T(t) - 50.
With rod #1 inserted, the temperature evolves according to \dot T(t) = 0.1 T(t) - 56, and with rod #2 inserted, the temperature evolves according to \dot T(t) = 0.1 T(t) - 60.
The initial temperature is 505 °C, with no rod inserted.
The system is controlled by a feedback control system that monitors the temperature and inserts or withdraws rods to keep the temperature within a safe range. The duration of the process of inserting or removing a rod is negligible compared to the time scale of the temperature evolution, so we can model it as a discrete event.
- A rod is inserted once the temperature rises to 550 °C.
- A rod is withdrawn once the temperature drops to 510 °C.
- After a given rod is withdrawn, that same rod must not be reinserted for at least 20 seconds. (The two rods have independent cooldown timers — withdrawing rod #2 does not restrict rod #1, and vice versa.)
- Whenever a rod must be inserted, the control system prefers rod #2; it inserts rod #1 only if rod #2 is currently unavailable (still cooling down).
- Identify the components of the hybrid automaton \{\mathcal Q, \mathcal Q_0, \mathcal X, \mathcal X_0, f, \mathcal I, \mathcal E, \mathcal G, \mathcal R\}.
- Draw the digraph (nodes, edges, labels). Mark the initial state.
- Timing constraints. A 20-second cooldown cannot be represented by \mathcal Q or \mathcal E alone — discrete locations only change via instantaneous transitions, and nothing in the formalism makes a location advance on its own as time passes. Explain briefly why this is the case. Then extend \mathcal X with the clock variable(s) needed to track each rod’s cooldown: state how many you need, their dynamics f, and how they are reset on each transition.
- Rod preference. Using the clock variable(s) from Q3, express “prefer rod #2, fall back to rod #1” as part of the guard set(s) \mathcal G for the relevant transition(s) out of the no-rod location.
Part B (computer implementation, choose one)
Option 1 — Stateflow. Build the simulation model in Stateflow. For the cooldown timers, you can use the built-in temporal logic operators (e.g., after(20,sec)) instead of declaring explicit continuous clock states — compare this with your answer to Q3: after() is effectively the same clock idea, just managed for you under the hood.
Option 2 — low-level MATLAB or Julia (no GUI). Implement the automaton directly via ODE integration with event detection:
- Represent the state as [T, \tau_1, \tau_2], where \tau_1,\tau_2 are the two cooldown clocks (each with \dot\tau_i = 1, reset to 0 when the corresponding rod is withdrawn).
- MATLAB: use
ode45withodeset('Events', @reactorEvents); your events function should return zero-crossings for (a) T=550, (b) T=510, restarting the integration after each detected event with the appropriate new mode and, where relevant, a rod-availability check (\tau_i \geq 20) to decide which rod to insert. - Julia: use
OrdinaryDiffEq.jlwith aVectorContinuousCallbackfor the same two conditions, with anaffect!that switches the active vector field and resets the corresponding \tau_i.
Since none of the transitions reset T itself (only the active dynamics and the clocks change), this is a comparatively clean case for the non-GUI track — similar in spirit to event-triggered integration you may use elsewhere in the course, but here with three simultaneous event conditions (temperature threshold plus two independent cooldown checks) rather than a single boundary, so budget extra time for getting the event/mode bookkeeping right.
For both options: simulate at least 3 minutes of reactor time from the given initial condition, and plot T(t) together with the active mode q(t) (and, if using Option 2, \tau_1(t), \tau_2(t)) to visually confirm the rod-preference and cooldown logic are behaving as intended.