Shapes & spaces

Constrained linear model predictive control calculator with a receding horizon

Simulate constrained receding-horizon linear MPC with condensed QPs and explicit primal-dual diagnostics.

Your numbers

Valid JSON. Discrete x_next=A*x+B*u. Q/R costs, state/input box bounds; constraints start at next state.
Valid JSON; preserve the shown array or object structure.
Valid JSON; preserve the shown array or object structure.
Valid JSON; preserve the shown array or object structure.
Valid JSON; preserve the shown array or object structure.
Valid JSON; preserve the shown array or object structure.
Valid JSON; preserve the shown array or object structure.

Calculated on your device. Your inputs aren’t sent to us.

Your result

Ready when you are

Enter your inputs and select Calculate.

Report an issue

Behind the numbers

How this calculation works

Model predictive control chooses a sequence of future control inputs by solving a finite-horizon optimization problem. Only the first input is applied. The state is then updated and the optimization is solved again from the new state.

THE FORMULACondenseddynamicsx_k=A^k x0+sumA^(k-1-j)Bu_j. Objective sumk0..N-1(xk-xref)^TQ(xk-xref)+uk^TRuk +terminalQN. HpositiveR; constraintsboxuandstate becomeG U<=h. Active-setQPwithfeasibilityphaseI, KKTcertprimal/dual/complementarity; bruteenumerationsmall<=? constraints24 controlvars impossible general requireproperactive-set. Statusoptimal,infeasiblecertified,unresolved distinct. Eachsimstepapplyonlyu0 thenrecomputeQP; actualrecedingupdatesnotoneopenloopsequence. x0constraintmustcheckedifincluded. Stateoffsetxrefinadynamics noerroriftargetnotsteady inform.

A worked example

With the prefilled inputs, states = [[1],[0.4000001430511474],[0.16000017166141783],[0.06400016021739971]]. Discrete x_next=A*x+B*u. Q/R costs, state/input box bounds; constraints start at next state.

Good to know

Discrete linear dynamics,receding finite horizon,fixed Q/R and box bounds;ADMM condensed convex QP accepted only after primal/dual/complementarity checks. No terminal invariant set,recursive-feasibility guarantee or exact infeasibility classification.

Planning repeatedly with constraints

Model predictive control chooses a sequence of future control inputs by solving a finite-horizon optimization problem. Only the first input is applied. The state is then updated and the optimization is solved again from the new state.

That repeated solve is the defining receding-horizon behavior. Plotting one open-loop plan without replanning does not demonstrate the same controller. This page uses a supplied linear discrete-time model and quadratic costs, not an automatically identified physical system.

Constrained linear model predictive control calculator with a receding horizonFirst MPC plan: a bounded scalar integrator10.750.5planned states k = 0,1,2u₀ = −0.25u₁ = −0.25Horizon 2; Q = R = QN = 1; first-plan cost = 0.9375
Scroll across to see the full diagram.
The plotted first plan forxnext=x+u has controls−1/4,−1/4 and states1,3/4,1/2, with total cost0.9375. Onlyu₀ is applied before a real receding-horizon controller must solve again.

Compare with the Discrete algebraic Riccati equation calculator. Optimizefinitehorizoninputsequenceunderstate/inputinequalitiesandapplyrecedingcontrol; unconstrainedLQRhasnosaturationconstraintorfeasibilitycontract.

Model, fixed zero target and bounds

Discrete x_next=A*x+B*u. Q/R costs, state/input box bounds; constraints start at next state.The matrices A and B give a discrete linear system with one through three states and one or two controls. Enter compatible Q and positive-definite R cost matrices, a finite initial state and strictly ordered box bounds for each state and input. The target is fixed at zero; there is no separate reference-state selector or independent terminal-weight input in this release.

The horizon ranges from two through twelve and the requested simulation from one through thirty steps. The objective penalizes the predicted states x1 through xN with the same Q and the controls u0 through uN−1 with R. Initial-state cost and a separate terminal invariant set are not added, so comparisons must use that specific indexing convention.

Condensing the trajectory

Repeated substitution expresses every future state as a linear function of the initial state and the stacked controls. The cost then becomes a quadratic function of those controls, while state and input bounds become linear inequalities.

This construction removes the dynamics equations from the optimizer without removing their effect. It needs careful indexing of the terminal state and running costs. An off-by-one error can produce a feasible plan for a different horizon than the interface promises.

ADMM convergence and unresolved problems

The condensed convex quadratic program is solved by an alternating-direction method with fixed penalty parameter and bounded iterations. A candidate step is accepted only when its inequality feasibility, stationarity and complementarity checks meet the numerical thresholds. The returned per-step data include the applied control, planned controls, primal residual, stationarity residual and iteration count.

This release does not produce an exact infeasibility certificate. If the quadratic program reaches its work cap, the failure is explicitly unresolved or infeasible, without choosing between those possibilities. The function stops rather than returning an uncertified controller step, and it does not export a partially completed simulation as a successful closed-loop trajectory.

A two-step integrator worked plan

Take the scalar model xnext=x+u with initial state one, Q=R=1, horizon two and loose bounds of minus ten to ten. Minimizing x1 squared plus x2 squared plus u0 squared plus u1 squared gives the exact first planned controls minus0.6 and minus0.2. The resulting planned states are one,0.4 and0.2.

Only minus0.6 is applied. At the next step the same optimization begins from0.4 and selects an applied input minus0.24, leading to state0.16. A third replan gives minus0.096 and state0.064. The numerical prefill approximates these values within its stopping tolerances; replaying the original second planned input would instead illustrate open-loop execution.

Reading the control and state plots

A useful static figure shows the actually applied controls and resulting states, with bounds drawn explicitly. Planned future values can be shown separately for a selected step. Mixing planned and applied values in one unlabeled curve can hide whether replanning occurred.

Per-step diagnostics include applied and planned controls, primal and stationarity residuals and iteration count; a scalar objective is not included in the returned step table. A low cost alone says little if constraints were violated. When a simulation stops because the next QP is unresolved or infeasible, preserve the successful prefix and clearly state why it ended.

What the finite horizon does not prove

Feasible optimization at the initial state does not automatically guarantee feasibility forever. Recursive feasibility and closed-loop stability usually require additional design assumptions, terminal ingredients or proofs. The page should not infer those properties from a short successful simulation.

The model excludes unmodeled disturbances unless they are explicitly supplied in a supported simulation mode. It is a numerical design aid for the entered linear system, not a safety certificate for a physical controller. Any implementation needs a separate validation process. Discrete linear dynamics,receding finite horizon,fixed Q/R and box bounds;ADMM condensed convex QP accepted only after primal/dual/complementarity checks. No terminal invariant set,recursive-feasibility guarantee or exact infeasibility classification.

A few questions, answered

Why apply only the first planned control?

The next optimization incorporates the updated state, which is the receding-horizon principle.

Does one feasible plan guarantee future feasibility?

No; recursive feasibility needs additional assumptions or design conditions.

Is a work-cap failure proof of infeasibility?

No; the ADMM implementation reports an unresolved-or-infeasible failure and does not produce an exact infeasibility certificate.

Can I choose a target or terminal penalty?

Not in this release: the target is zero and the same Q weights x1 through xN, with no independently selected terminal weight.

Find your calculator

Start typing to explore the library.