Process: K = 2, T = 5 s, dt = 0.1 s (fixed). Simulation horizon 15 s. The same plant is also controlled by a PID (Kp = 2, Ki = 0.4) for comparison.
Top: y (blue), r (dashed red), PID response (gray), predicted horizon (dotted blue). Bottom: u (green), Nc optimized inputs (yellow dots).
Discretize the first-order process $G_p(s) = K/(T s + 1)$ with a forward Euler step to obtain $x_{k+1} = a\,x_k + b\,u_k$ where $a = e^{-dt/T}$ and $b = K(1-a)$.
Prediction over $N_p$ steps:
$$y_{k+i} = a^{i}\,x_k + \sum_{j=0}^{i-1} a^{i-1-j}\,b\,u_{k+j}$$Cost (output error + Δu penalty for offset-free tracking):
$$J = \sum_{i=1}^{N_p} (y_{k+i} - r)^2 + \lambda \sum_{j=0}^{N_c - 1} (\Delta u_{k+j})^2$$Closed-form solution of the unconstrained QP ($\partial J / \partial U = 0$):
$$U = \bigl(H^\top H + \lambda\, L^\top L\bigr)^{-1} \bigl(H^\top (R - F\,x_k) + \lambda\,u_{k-1}\,\mathbf{e}_1\bigr)$$$H$ ($N_p \times N_c$) and $F$ ($N_p \times 1$) are built from $a, b$, and $L$ is the first-difference operator. Only the first entry $u_k = U[0]$ is applied to the plant (receding horizon) and the optimization is repeated next step.