A First MPC, and a Model That Goes Stale
Open the Two-Tank Level Control Studio app
Advanced Control Exercise 16 of 30 in Linear MPC · All exercises · Time: 15 minutes
A pump fills an upper tank that drains into a lower one, and a splitter valve can send part of the flow straight to the lower tank. The splitter does not change the steady level. It changes how fast pump flow arrives, which is exactly what a predictive controller's model is about. This exercise runs a first MPC, lets the plant leave its model, and fixes it with a model chosen by the splitter setting.
Learning Outcomes
- Write the linear MPC problem as a quadratic program in the future input moves.
- Explain how the receding horizon and a disturbance estimate remove offset, and why a model with the wrong speed still rings.
- Compare a fixed-model MPC, a scheduled-model MPC and a PID on the same plant change.
Book Chapter
Process Dynamics, Modeling, and Identification (Volume 1), Chapter 3, Two-Tank Level Control With a Splitter Valve That Sets the Plant Order. Read the chapter, open the PDF, or watch the lecture slides.
Theory in Brief
The MPC plans the next `M` pump moves to bring the predicted lower level `\hat y` to the setpoint `r` over `N` steps. The weights `Q` and `R` price level error and moves:
$$\begin{gathered} \min_{\Delta u_0,\ldots,\Delta u_{M-1}} \sum_{k=1}^{N} \left\| \hat y_k - r_k \right\|^2_{Q} + \sum_{k=0}^{M-1} \left\| \Delta u_k \right\|^2_{R} \\ \mathrm{s.t.}\quad x_{k+1} = A x_k + B (u_k + d),\;\; \hat y_k = C x_k,\;\; 0 \le u_k \le 100\% \end{gathered}$$
A Kalman filter estimates the state `\hat x_0` and an input disturbance `\hat d` from the measured level. Substituting the model gives a quadratic program in the move vector `z`:
$$\begin{gathered} \min_{z} \; \tfrac{1}{2} z^T H z + g^T z \\ \mathrm{s.t.}\quad G z \le h, \\ H = \Phi^T Q \Phi + R, \quad g = \Phi^T Q \left(\Gamma \hat x_0 + \Lambda u_{-1} + \Psi \hat d - r\right) \end{gathered}$$
`\Phi` holds the step-response coefficients, `\Gamma`, `\Lambda` and `\Psi` carry the state, the last move `u_{-1}` and the disturbance into the prediction. Only the first move is applied, and the plan is made again next sample. The disturbance estimate removes steady offset. It cannot fix a model whose speed is wrong: each plan expects the water to arrive later than it does, overshoots, and the next plan reverses it. A scheduled model keeps one identified model per splitter opening `\sigma` and plans with `(A_\sigma, B_\sigma, C_\sigma)`.
Model: Data-driven. Linear models identified from step tests with the splitter shut and at 25, 50, 75 and 100 %; the plant is the nonlinear two-tank balance.
Decision: The pump output every sample, from a quadratic program over the prediction horizon.
Learning: System identification is the learning step; the scheduled model is a lookup of models learned at five operating points.
Exercise
Read 2 min · Predict 1 min · Run 7 min · Explain 3 min · Check your AI 2 min.
Predict. The splitter does not change the steady level, only the path the water takes. Will an MPC that plans with a model of the shut splitter notice the difference after the splitter opens? Write down which you expect to win, the MPC or the PID.
Run the Two-Tank Level Control Studio app. Use the fastest speed, 10×, and press Run again to pause at the times in each step.
- Open 9 · MPC when the splitter reshapes the plant. The MPC is in charge in Auto. Press Run and pause at 300 s (5.00 min): the splitter opens to 50 % at 10 s and the setpoint steps to 0.60 m at 60 s. Watch the pump and read the IAE for the lower tank level in the Control performance tiles.
- Set Controller to PID, press Reset, and run the same case to 300 s. Read the IAE again.
- Open 10 · Scheduled model: the MPC follows the splitter: the same MPC with Model set to Scheduled (Advanced). Run it to 300 s and read the IAE.
Explain.
- Why does the fixed-model MPC lose to a PID that assumes no model at all?
- What did the scheduled model change, and what is left that no model choice can remove?
Generative AI Learning
Check the answer against your run: A good answer blames the model's speed, not the tuning, and proposes re-identifying at the new setting. Your step 3 run tests it: the controller and tuning are unchanged, only the model. The assistant is your tutor and reviewer; you answer for every claim you turn in.
What to Turn In
A table with one row per run and the numbers each step asks you to read, your written prediction, and three sentences that answer the two questions.

The fixed-model MPC rings. The pump swings between its limits, the level cycles around 0.60 m, and the lower tank level IAE is 8.68 m·s over 300 s. The PID holds the new setpoint with an IAE of 3.14 m·s. The MPC's model says pump flow reaches the lower tank only through the upper one. With the splitter half open it arrives sooner, so every plan overshoots and the next one reverses it. The disturbance estimate keeps the average level right, but each new plan uses the same wrong speed.
Told the splitter setting, the MPC plans on the model identified at 50 % and the IAE falls to 1.53 m·s, below the PID's. What remains is the moment the splitter moves: the model switches at once, while the water takes a few seconds to redistribute, and the estimator books that transient as load. More move suppression would slow the swings of step 1 but not remove the model error.
Measured with the app build of December 3, 2026 by a scripted replay of the steps above. Numbers that no tile shows come from the replay's record; your readings from the trends will be close. A later app release may move the last digit.
TCLab F builds a linear MPC in GEKKO. Identify an ARX model from a step test, then simulate the MPC against a plant whose time constant is half the model's. Plot the input. The ringing you saw here is what `\Phi` computed from the wrong model does.
Related
- Check yourself: three-question quiz
- Course pages: Model Predictive Control, Control Tuning, MIMO Model ID, TCLab F
- Exercises: previous: 15 · A Constrained Landing Trajectory; next: 17 · MPC Behind a Dead Time
References
- Hedengren, J. D. (ed.), Process Dynamics, Modeling, and Identification, Volume 1 of Interactive Control Engineering, Chapter 3, "Two-Tank Level Control With a Splitter Valve That Sets the Plant Order", pp. 53–83, Advanced Process Solutions, 2026. PDF (CC BY 4.0).
- Qin, S. J., Badgwell, T. A., A survey of industrial model predictive control technology, Control Engineering Practice 11(7), 733–764, 2003.
