Part: control Week 15 Published mpc.jl runtests.jl

Model Predictive Control: Receding-Horizon Optimization as Implicit Feedback

Model predictive control as online approximate dynamic programming: the constrained finite-horizon optimal-control problem solved as a quadratic program at every state, the first move applied and the problem re-solved (receding horizon). With the LQR cost-to-go as terminal cost the finite horizon recovers LQR exactly; terminal ingredients (a terminal cost and an invariant terminal region) make the MPC value function a Lyapunov function, delivering closed-loop stability and recursive feasibility — Chapter 1's Bellman equation run online over a horizon, with constraints as first-class citizens.

On this page
  1. From one gain to a horizon of decisions
  2. The terminal cost that recovers LQR
  3. Terminal ingredients
  4. Stability: the value function is a Lyapunov function
  5. Recursive feasibility
  6. MPC as online approximate dynamic programming
  7. What’s next
  8. Exercises
  9. Companion code

Model Predictive Control: Receding-Horizon Optimization as Implicit Feedback

Where we are. Chapter 13 solved the unconstrained linear-quadratic problem in closed form: one algebraic Riccati equation gives a single feedback gain K\lqrgain good for all time. But real actuators saturate, real states have limits, and the moment a constraint is present the Riccati equation has nothing to say — there is no closed form. Model predictive control (MPC) answers with a different idea: do not precompute one feedback law. Instead, at the current state, solve a finite-horizon optimal-control problem numerically, apply only its first move, and at the next state solve it again. The optimization is the controller — feedback by re-solving. This is the most widely deployed advanced control method in industry García et al. (1989) , and, read through Chapter 1, it is dynamic programming run online: an N\horizon-step Bellman lookahead with the LQR cost-to-go grafted on as a terminal estimate.

From one gain to a horizon of decisions

Chapter 13 minimized a quadratic cost over an infinite horizon and got a stationary gain. MPC keeps the quadratic cost but makes three moves: it (i) truncates the horizon to a finite N\horizon, (ii) adds hard constraints hkX\statevec_k\in\xset, ukUu_k\in\uset, and (iii) re-solves at every state rather than precomputing. The price of constraints is the loss of a closed form; the payment is a numerical optimization at each step — for linear dynamics and a quadratic cost, a quadratic program (QP), which modern solvers dispatch in microseconds Stellato et al. (2020) .

Definition 15.1 (Constrained finite-horizon MPC).

For the system hk+1=Ahk+Buk\statevec_{k+1}=\statemat\statevec_k+\inputmat u_k with stage cost (h,u)=hQh+uRu\ell(\statevec,u)=\statevec^\top Q\statevec+u^\top R u (Q0Q\succeq0, R0R\succ0) and terminal cost F(h)=hPfhF(\statevec)=\statevec^\top \riccati_f\statevec, the MPC value function at state h\statevec is

VN(h)=minu0,,uN1 k=0N1(hk,uk)+F(hN),\mpcvalue(\statevec)=\min_{u_0,\dots,u_{\horizon-1}}\ \sum_{k=0}^{\horizon-1}\ell(\statevec_k,u_k)+F(\statevec_\horizon),

subject to h0=h\statevec_0=\statevec, the dynamics hk+1=Ahk+Buk\statevec_{k+1}=\statemat\statevec_k+\inputmat u_k, and the constraints hkX\statevec_k\in\xset, ukUu_k\in\uset, hNXf\statevec_\horizon\in\termset (the terminal set, made precise in Definition 15.2). The MPC control law is the first optimal move, πN(h)=u0(h)\policy_\horizon(\statevec)=u_0^\star(\statevec), applied to give the closed loop h+=Ah+BπN(h)\statevec^+=\statemat\statevec+\inputmat\,\policy_\horizon(\statevec).

With X,U,Xf\xset,\uset,\termset polyhedral (box bounds, here), the problem is a convex QP: a quadratic objective in the stacked decision variables subject to linear equality (dynamics) and inequality (constraints) constraints.

The companion builds it with JuMP and solves it with OSQP, a first-order operator-splitting solver Stellato et al. (2020) .

The terminal cost that recovers LQR

Before stability, a sanity check that ties MPC to Chapter 13. Strip the constraints and set the terminal cost to the LQR cost-to-go. The finite horizon then collapses to the infinite-horizon answer — for any horizon length.

Proposition 15.1 (MPC reproduces LQR).

Let P\riccati be the stabilizing solution of the discrete algebraic Riccati equation (Chapter 13, under stabilizability of (A,B)(\statemat,\inputmat) and detectability of (A,Q1/2)(\statemat,Q^{1/2})) with gain K=(R+BPB)1BPA\lqrgain=(R+\inputmat^\top\riccati\inputmat)^{-1}\inputmat^\top\riccati\statemat. If the terminal cost uses Pf=P\riccati_f=\riccati and no inequality constraint is active at the optimum, then for every horizon N1\horizon\geq1 the MPC law is the LQR law, πN(h)=Kh\policy_\horizon(\statevec)=-\lqrgain\statevec.

Proof.

Without active inequalities the problem of Definition 15.1 is the unconstrained finite-horizon LQR of Chapter 13, whose solution is the backward Riccati recursion PN=Pf\riccati_\horizon=\riccati_f, Pk=Q+APk+1AAPk+1B(R+BPk+1B)1BPk+1A\riccati_{k}=Q+\statemat^\top\riccati_{k+1}\statemat-\statemat^\top\riccati_{k+1}\inputmat(R+\inputmat^\top\riccati_{k+1}\inputmat)^{-1}\inputmat^\top\riccati_{k+1}\statemat. Initialize it at Pf=P\riccati_f=\riccati. Because P\riccati solves the DARE, it is a fixed point of the Riccati map, so Pk=P\riccati_{k}=\riccati for all kk — the recursion never moves. The first-step gain is therefore K0=(R+BPB)1BPA=K\lqrgain_0=(R+\inputmat^\top\riccati\inputmat)^{-1}\inputmat^\top\riccati\statemat=\lqrgain, and the applied move is u0=Khu_0^\star=-\lqrgain\statevec regardless of N\horizon. \qquad\blacksquare

The terminal cost is doing the work: setting it to the exact optimal cost-to-go makes one step of lookahead see the entire infinite future, so the horizon length stops mattering.

This is the first appearance of the chapter’s thesis: a good terminal cost is a value-function estimate, and the better the estimate, the shorter the horizon you need. With constraints the exact cost-to-go is unavailable in closed form, so we keep P\riccati as a local terminal estimate and lean on the horizon to handle the rest.

Terminal ingredients

The recursive structure that made Proposition 15.1 work — appending the local LQR move at the end — is exactly what stability needs. Mayne et al. (2000) distilled it into two terminal ingredients: a terminal cost and a terminal set, compatible with a local controller (the textbook synthesis is Rawlings et al. (2017) ).

Definition 15.2 (Admissible terminal ingredients).

A terminal cost F(h)=hPhF(\statevec)=\statevec^\top\riccati\statevec and terminal set Xf\termset are admissible for a local controller κf\kappa_f if, for all hXf\statevec\in\termset: (i) constraint compatibilityXfX\termset\subseteq\xset and κf(h)U\kappa_f(\statevec)\in\uset; (ii) invarianceAh+Bκf(h)Xf\statemat\statevec+\inputmat\kappa_f(\statevec)\in\termset; (iii) cost decreaseF(Ah+Bκf(h))F(h)(h,κf(h))F(\statemat\statevec+\inputmat\kappa_f(\statevec))-F(\statevec)\leq-\ell(\statevec,\kappa_f(\statevec)).

For the linear-quadratic problem there is a canonical choice: take κf(h)=Kh\kappa_f(\statevec)=-\lqrgain\statevec (the LQR law), F(h)=hPhF(\statevec)=\statevec^\top\riccati\statevec (the DARE cost-to-go), and Xf={h:hPhc}\termset=\{\statevec:\statevec^\top\riccati\statevec\leq c\}, the Lyapunov sublevel set on which Kh-\lqrgain\statevec respects the constraints. Condition (iii) then holds with equality: the DARE rearranges to (ABK)P(ABK)P=(Q+KRK)(\statemat-\inputmat\lqrgain)^\top\riccati(\statemat-\inputmat\lqrgain)-\riccati=-(Q+\lqrgain^\top R\lqrgain), which is exactly F(h+)F(h)=(h,Kh)F(\statevec^+)-F(\statevec)=-\ell(\statevec,-\lqrgain\statevec) along the local closed loop — the same Lyapunov identity proved in Chapter 13. Invariance follows from that identity: on Xf\termset the local closed loop gives F(h+)F(h)cF(\statevec^+)\leq F(\statevec)\leq c, so h+Xf\statevec^+\in\termset; and constraint compatibility holds because cc is chosen small enough that Kh-\lqrgain\statevec stays within the input box — and, if a state box is present, Xf\termset within it — everywhere on Xf\termset (the companion’s terminal_region computes the largest such cc, taking both bounds into account).

One caveat the companion makes concrete. The set Xf={h:hPhc}\termset=\{\statevec:\statevec^\top\riccati\statevec\leq c\} is quadratic, so imposing the terminal constraint hNXf\statevec_\horizon\in\termset of Definition 15.1 literally would make the program a QCQP — which the QP solver OSQP cannot take. The companion therefore imposes the terminal cost (and, for the feasibility study, a linear terminal box as a concrete admissible surrogate for Xf\termset) and verifies Xf\termset-invariance of the realized closed loop rather than encoding it as a constraint. This suffices for the MPC\equivLQR and stability demonstrations, which need only the terminal cost; the terminal-set constraint is what the general recursive-feasibility theorem below requires.

Stability: the value function is a Lyapunov function

With admissible terminal ingredients the descent argument of Chapter 14 transfers wholesale, but now the certificate is the optimization value VN\mpcvalue itself. The engine is a single feasible candidate built by shifting the previous solution.

Lemma 15.1 (Value descent).

Under admissible terminal ingredients, for every feasible state h\statevec,

VN(Ah+BπN(h))  VN(h)(h,πN(h)).\mpcvalue(\statemat\statevec+\inputmat\,\policy_\horizon(\statevec))\ \leq\ \mpcvalue(\statevec)-\ell(\statevec,\policy_\horizon(\statevec)).
Proof.

Let u=(u0,,uN1)u^\star=(u_0^\star,\dots,u_{\horizon-1}^\star) be optimal at h\statevec, with predicted states h0=h,,hN\statevec_0=\statevec,\dots,\statevec_\horizon, so VN(h)=k=0N1(hk,uk)+F(hN)\mpcvalue(\statevec)=\sum_{k=0}^{\horizon-1}\ell(\statevec_k,u_k^\star)+F(\statevec_\horizon). At the successor h+=h1\statevec^+=\statevec_1 form the shifted candidate u~=(u1,,uN1,κf(hN))\tilde u=(u_1^\star,\dots,u_{\horizon-1}^\star,\kappa_f(\statevec_\horizon)): replay the tail of the optimal plan, then append the local controller. It is feasible — the first N1\horizon-1 moves reuse states h2,,hN\statevec_2,\dots,\statevec_\horizon that already satisfy the constraints, and by invariance hNXf\statevec_\horizon\in\termset gives AhN+Bκf(hN)XfX\statemat\statevec_\horizon+\inputmat\kappa_f(\statevec_\horizon)\in\termset\subseteq\xset with κf(hN)U\kappa_f(\statevec_\horizon)\in\uset. Evaluating the objective on u~\tilde u replays stages 1,,N11,\dots,\horizon-1 of uu^\star and appends the local step, so its cost is

k=1N1(hk,uk)+(hN,κf(hN))+F(hN+1),hN+1=AhN+Bκf(hN).\sum_{k=1}^{\horizon-1}\ell(\statevec_k,u_k^\star)+\ell(\statevec_\horizon,\kappa_f(\statevec_\horizon))+F(\statevec_{\horizon+1}),\qquad\statevec_{\horizon+1}=\statemat\statevec_\horizon+\inputmat\kappa_f(\statevec_\horizon).

The optimal cost is VN(h)=k=0N1(hk,uk)+F(hN)\mpcvalue(\statevec)=\sum_{k=0}^{\horizon-1}\ell(\statevec_k,u_k^\star)+F(\statevec_\horizon); the two sums share stages 1,,N11,\dots,\horizon-1, so the candidate cost equals VN(h)(h0,u0)+[F(hN+1)F(hN)+(hN,κf(hN))]\mpcvalue(\statevec)-\ell(\statevec_0,u_0^\star)+[\,F(\statevec_{\horizon+1})-F(\statevec_\horizon)+\ell(\statevec_\horizon,\kappa_f(\statevec_\horizon))\,]. Since VN(h+)\mpcvalue(\statevec^+) is the minimum over feasible plans, it is no larger than this candidate’s cost:

VN(h+)VN(h)(h,u0)+[F(AhN+Bκf(hN))F(hN)+(hN,κf(hN))]0 by (iii).\mpcvalue(\statevec^+)\leq\mpcvalue(\statevec)-\ell(\statevec,u_0^\star)+\underbrace{\big[F(\statemat\statevec_\horizon+\inputmat\kappa_f(\statevec_\horizon))-F(\statevec_\horizon)+\ell(\statevec_\horizon,\kappa_f(\statevec_\horizon))\big]}_{\leq\,0\ \text{by (iii)}}.

Since u0=πN(h)u_0^\star=\policy_\horizon(\statevec) and the bracket is non-positive, VN(h+)VN(h)(h,πN(h))\mpcvalue(\statevec^+)\leq\mpcvalue(\statevec)-\ell(\statevec,\policy_\horizon(\statevec)). \qquad\blacksquare

Theorem 15.1 (Closed-loop asymptotic stability).

Under admissible terminal ingredients and Q0Q\succ0, the origin is asymptotically stable for the MPC closed loop, with region of attraction the feasible set XN\xset_\horizon (the states from which the N\horizon-step problem is feasible). For merely Q0Q\succeq0 the same conclusion holds when (A,Q1/2)(\statemat,Q^{1/2}) is detectable, through a LaSalle argument as in Chapter 14.

Proof.

VN\mpcvalue is a Lyapunov function on XN\xset_\horizon. It is positive definite: VN(h)(h,πN(h))λmin(Q)h2\mpcvalue(\statevec)\geq\ell(\statevec,\policy_\horizon(\statevec))\geq\lambda_{\min}(Q)\norm{\statevec}^2, and on Xf\termset it is bounded above by F(h)=hPhλmax(P)h2F(\statevec)=\statevec^\top\riccati\statevec\leq\lambda_{\max}(\riccati)\norm{\statevec}^2. Lemma 15.1 gives VN(h+)VN(h)(h,πN(h))λmin(Q)h2<0\mpcvalue(\statevec^+)-\mpcvalue(\statevec)\leq-\ell(\statevec,\policy_\horizon(\statevec))\leq-\lambda_{\min}(Q)\norm{\statevec}^2<0 for h0\statevec\neq0. Positive-definiteness, the local upper bound on Xf\termset, and this strict descent are the hypotheses of the discrete Lyapunov theorem (Chapter 14), so the origin is asymptotically stable. Because XN\xset_\horizon is positively invariant (Theorem 15.2) and the value strictly descends on it, every feasible trajectory enters Xf\termset and converges — the region of attraction is all of XN\xset_\horizon. \qquad\blacksquare

The proof is Chapter 14’s Lyapunov argument with V=VN\lyap=\mpcvalue, and the descent quantity is the stage cost — the same accounting as the LQR Lyapunov identity, now carried by the optimization rather than a fixed gain. The companion runs the closed loop on the double integrator and samples exactly this: the realized state goes to zero, VN\mpcvalue is non-increasing step to step, the quadratic hPh\statevec^\top\riccati\statevec strictly decreases, and once the trajectory enters Xf\termset it never leaves.

Left: a phase-plane trajectory curving inward from the start state to the origin, entering an ellipse that marks the terminal region. Right: two monotonically decreasing curves on a log scale, the MPC value and the terminal-cost quadratic, versus step.
Constrained MPC on the discrete double integrator (terminal cost = DARE solution P, input bound |u| ≤ 1). Left: the closed-loop trajectory converges to the origin and enters the terminal region Ω = {x : xᵀP x ≤ c} (ellipse), which the realized closed loop never leaves — illustrating the invariance of Definition 15.2(ii). Right: the MPC value V_N and the terminal-cost Lyapunov function xᵀP x both decrease monotonically along the closed loop (Lemma 15.1, Theorem 15.1). Produced by experiments/python/week15/make_fig.py from the Julia companion's exported trajectory.

Recursive feasibility

Stability assumed the problem stays solvable. That is not automatic — a feasible problem now can become infeasible next step if a constraint cannot be honored from the successor state. The shifted candidate of Lemma 15.1 settles it: it is a feasible plan at the successor, so feasibility propagates.

Theorem 15.2 (Recursive feasibility).

Under admissible terminal ingredients, if the MPC problem is feasible at h0\statevec_0 it is feasible at every subsequent closed-loop state: h0XN\statevec_0\in\xset_\horizon implies hkXN\statevec_k\in\xset_\horizon for all k0k\geq0. The feasible set XN\xset_\horizon grows with the horizon, XNXN+1\xset_\horizon\subseteq\xset_{\horizon+1}.

Proof.

The shifted candidate u~\tilde u constructed in Lemma 15.1 satisfies every constraint of the problem at h+\statevec^+, so h+XN\statevec^+\in\xset_\horizon — one feasible step certifies the next. Induction gives feasibility for all kk. For the monotonicity, any feasible N\horizon-step plan extends to a feasible (N+1)(\horizon{+}1)-step plan by appending κf\kappa_f at the (invariant) terminal state, so XNXN+1\xset_\horizon\subseteq\xset_{\horizon+1}. \qquad\blacksquare

The growth of XN\xset_\horizon with N\horizon is the practical knob: a state too far from the origin to be steered into the terminal region within a short horizon becomes reachable as the horizon lengthens. The companion demonstrates both directions — a tight terminal box with a far initial state is infeasible at a short horizon (the solver reports infeasibility and the code raises, never silently returning a bad move) and feasible once the horizon is long enough.

MPC as online approximate dynamic programming

This is the chapter the title promised. Set the two computations side by side.

  • Chapter 1 (exact DP). The optimal cost-to-go solves the Bellman equation v(h)=minu[(h,u)+v(Ah+Bu)]\optvaluefn(\statevec)=\min_u[\,\ell(\statevec,u)+\optvaluefn(\statemat\statevec+\inputmat u)\,] (the deterministic, undiscounted cost form of Chapter 1’s v=Tv\optvaluefn=\bellmanopt\optvaluefn), and the optimal policy is its one-step greedy minimizer. With constraints, v\optvaluefn has no closed form and the state space is continuous — exact DP is intractable.
  • Chapter 15 (MPC). Replace the unknown tail v\optvaluefn by a finite unrolling plus a terminal estimate FF: VN(h)=min[k=0N1(hk,uk)+F(hN)]\mpcvalue(\statevec)=\min[\sum_{k=0}^{\horizon-1}\ell(\statevec_k,u_k)+F(\statevec_\horizon)], and apply the one-step minimizer πN(h)=u0\policy_\horizon(\statevec)=u_0^\star.

MPC is therefore one Bellman step taken online, with the genuinely-optimal tail approximated by N1\horizon-1 exact steps and a terminal cost-to-go estimate. The horizon and the terminal estimate trade off: a perfect estimate needs no horizon (Proposition 15.1, where F=vF=\optvaluefn makes N=1\horizon=1 exact), and a longer horizon forgives a cruder estimate. This is precisely “approximation in value space” — lookahead minimization over a terminal value approximation — the unifying view of Bertsekas’s reinforcement-learning-and-optimal-control program, which the convergence weeks take up directly (Week 19 reads MPC, rollout, and approximate policy iteration as one algorithm). The terminal cost is where a learned value function will later be grafted in: replace the LQR hPh\statevec^\top\riccati\statevec with a neural critic and MPC becomes a model-based RL controller — the MPC/RL hybrids of Part III. Chapter 13’s P\riccati is the value function; Chapter 14’s Lyapunov certificate is the terminal cost; Chapter 1’s Bellman step is the online minimization. Three chapters, one equation, now solved with constraints.

What’s next

  • Week 16 (nonlinear and robust MPC). Drop linearity: the QP becomes a nonlinear program (direct multiple shooting, SQP/interior-point), and the terminal-ingredient theorem generalizes to the quasi-infinite-horizon scheme. Robust and tube MPC tighten constraints against disturbances to recover the guarantees this chapter proved only for the nominal model — closing the optimality-is-not-robustness gap. The recent-developments survey Mayne (2014) maps the territory.

Exercises

  1. (Derive) Show that initializing the backward Riccati recursion at Pf=P\riccati_f=\riccati (the DARE solution) leaves every iterate equal to P\riccati, and conclude the MPC law equals Kh-\lqrgain\statevec for all N\horizon.

    Solution

    The DARE states P=Q+APAAPB(R+BPB)1BPA\riccati=Q+\statemat^\top\riccati\statemat-\statemat^\top\riccati\inputmat(R+\inputmat^\top\riccati\inputmat)^{-1}\inputmat^\top\riccati\statemat, i.e. P\riccati is a fixed point of the Riccati map R\mathcal{R}. The recursion is Pk=R(Pk+1)\riccati_k=\mathcal{R}(\riccati_{k+1}) with PN=P\riccati_\horizon=\riccati, so PN1=R(P)=P\riccati_{\horizon-1}=\mathcal{R}(\riccati)=\riccati and by induction Pk=P\riccati_k=\riccati for all kk. The first gain is then the stationary K\lqrgain, so u0=Khu_0^\star=-\lqrgain\statevec independent of N\horizon.

  2. (Prove) Establish the value-descent inequality (Lemma 15.1) by constructing the shifted candidate and bounding its cost. Where is each terminal-ingredient axiom used?

    Solution

    With optimal uu^\star and states h0,,hN\statevec_0,\dots,\statevec_\horizon at h\statevec, take u~=(u1,,uN1,κf(hN))\tilde u=(u_1^\star,\dots,u_{\horizon-1}^\star,\kappa_f(\statevec_\horizon)) at h+=h1\statevec^+=\statevec_1. Feasibility of the first N1\horizon-1 moves is inherited from uu^\star; (i) and (ii) make the appended step feasible and keep the new terminal state in Xf\termset. The cost of u~\tilde u is VN(h)(h,u0)+F(hN+1)F(hN)+(hN,κf(hN))\mpcvalue(\statevec)-\ell(\statevec,u_0^\star)+F(\statevec_{\horizon+1})-F(\statevec_\horizon)+\ell(\statevec_\horizon,\kappa_f(\statevec_\horizon)); axiom (iii) makes the last three terms 0\leq0. Since VN(h+)\mpcvalue(\statevec^+) is the minimum, it is \leq this candidate cost, giving the inequality.

  3. (Compute) For a single-input system with DARE solution P\riccati and gain K\lqrgain, find the largest cc such that Khumax|{-}\lqrgain\statevec|\leq u_{\max} on the sublevel set {h:hPhc}\{\statevec:\statevec^\top\riccati\statevec\leq c\}.

    Solution

    Maximize (Kh)2(\lqrgain\statevec)^2 over hPhc\statevec^\top\riccati\statevec\leq c. With y=P1/2hy=\riccati^{1/2}\statevec the objective is (KP1/2y)2(\lqrgain\riccati^{-1/2}y)^2 over y2c\norm{y}^2\leq c, whose max is cKP1Kc\,\lqrgain\riccati^{-1}\lqrgain^\top (Cauchy–Schwarz). Setting this umax2\leq u_{\max}^2 gives c=umax2/(KP1K)c=u_{\max}^2/(\lqrgain\riccati^{-1}\lqrgain^\top) — exactly the companion’s terminal_region.

  4. (Implement) In the companion, verify the MPC\equivLQR identity on both rails: the analytic condensed-QP solve to 10910^{-9} and OSQP to 10610^{-6}, across several horizons and initial states.

    Solution

    See experiments/julia/week15/runtests.jl: with terminal cost P\riccati from dare_gain, kkt_solve_unconstrained returns u0=Kh0u_0=-\lqrgain\statevec_0 to atol=1e-9 and solve_mpc (OSQP, polished, tight tolerances) to atol=1e-6, for N{1,2,3,5,10,25}\horizon\in\{1,2,3,5,10,25\} and four initial states — Proposition 15.1 confirmed and the two-rail tolerance discipline made explicit.

  5. (Extend) Demonstrate recursive feasibility numerically: pick a tight terminal box and a far initial state, show the short-horizon problem is infeasible and a long-horizon one feasible, and relate this to XNXN+1\xset_\horizon\subseteq\xset_{\horizon+1}.

    Solution

    See the companion’s feasibility test: from h0=(10,0)\statevec_0=(10,0) with u1|u|\leq1 and terminal box hN0.5|\statevec_\horizon|\leq0.5, solve_mpc raises at N=5\horizon=5 (OSQP reports infeasible) and succeeds at N=40\horizon=40, with the terminal box met. The far state is outside X5\xset_5 but inside X40\xset_{40}; since the feasible set grows with the horizon, lengthening it admits states a short horizon cannot steer into Xf\termset in time.

  6. (Extend) Read MPC as one step of value iteration with an inexact terminal value. When is the first move exactly optimal for the infinite-horizon problem, and what does the gap between FF and v\optvaluefn cost?

    Solution

    MPC applies the greedy minimizer of k<N+F(hN)\sum_{k<\horizon}\ell+F(\statevec_\horizon), which is the N\horizon-step Bellman lookahead with tail estimate FF. If F=vF=\optvaluefn the lookahead is exact at N=1\horizon=1 (Proposition 15.1 is the unconstrained instance, F=hPhF=\statevec^\top\riccati\statevec). When FvF\neq\optvaluefn — the generic constrained case — the first move is suboptimal for the infinite horizon by an amount that shrinks as N\horizon grows (more exact steps before the estimate is used) or as FF better approximates v\optvaluefn. This is the approximation-in-value-space tradeoff Part III exploits by learning FF.

Companion code

The Week-15 companion lives at experiments/julia/week15/ — the control lane is Julia-native from here (JuMP for modeling, OSQP for the QP), building on the tested dare_gain from experiments/julia/week13/. It pins the same discrete double-integrator literals as the Week-13 LQR suite, so the MPC results are parity-locked to the already-verified LQR/DARE base.

  • mpc.jlbuild_mpc_qp / solve_mpc (the OSQP rail; solve_mpc raises on any non-optimal termination); receding_horizon (closed-loop simulation recording the MPC value VN\mpcvalue); kkt_solve_unconstrained (the condensed dense solve — the 10910^{-9} analytic rail); and terminal_region (the largest admissible sublevel-set cc).
  • runtests.jl — mathematical-correctness tests: the MPC\equivLQR identity on both rails (Proposition 15.1); constraints binding with cost \leq the saturated-LQR rollout; closed-loop stability with VN\mpcvalue non-increasing, hPh\statevec^\top\riccati\statevec decreasing, and Xf\termset invariant (Lemma 15.1, Theorem 15.1); and recursive feasibility — infeasible at a short horizon, feasible at a long one (Theorem 15.2).
# linear-MPC companion: QP build/solve, two-rail parity, stability, feasibility
julia --project=experiments/julia experiments/julia/week15/runtests.jl

# the whole Julia control lane (weeks 11–15) in one aggregator run
make test-julia

The chapter figure is generated from the companion’s exported trajectory:

# export the closed-loop trajectory + terminal region, then render the figure
python experiments/python/week15/make_fig.py