Quadratic Program — Control Systems/Optimization
Control_Systems/Optimization/Quadratic_Program · 2 input / 3 output port(s) at insert · exports to Python, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog, PLC Structured Text
Description#
The block's own DESCRIPTION_HTML, rendered verbatim — the same text the config dialog's info panel and the library navigator show. Fix a wrong sentence in the block's .cpp (R-D9), never here.
Quadratic Program
Control Systems / Optimization
Solves minx ½·x'H·x + f'·x subject to
Aeq·x = beq, A·x ≤ b and lb ≤ x ≤ ub on every step
– MATLAB's quadprog. H and the constraint matrices are settings; the
linear term f and the inequality right-hand side b arrive on ports, which is the
split a model-predictive controller needs: the condensed Hessian and constraint matrix are fixed
by the horizon and the model, while f and b are recomputed from the state at every step. The
method is the Goldfarb-Idnani dual active set: it starts at the unconstrained minimizer
−H−1f, adds the most violated constraint, and drops whichever active
constraint's multiplier would turn negative first.
Ports
- f – the linear term, an [n,1] column with one entry per variable (the size of H).
- b – the right-hand side of A·x ≤ b, a [p,1] column with one entry per row of A. When A is empty this port is unused and must be connected to any [1,1] signal.
- x – the minimizer, [n,1].
- fval – the objective at x, ½·x'H·x + f'·x, [1,1].
- exitflag – [1,1], with MATLAB's values: 1 optimal, 0 the iteration limit was reached, −2 the constraints are infeasible. Read it before using x.
Parameters
- Options – empty (default), or the path of a Solver Options block (
Home/Solver Options), MATLAB’s options argument: for the run, every option it sets replaces this block’s parameter of the same name; one it leaves atdefault, or one this block does not have, changes nothing. - Hessian Matrix H – the Hessian, [n,n] with at most 12 variables. It is symmetrized as
quadprogdoes, (H+H')/2, and must be positive definite: this block solves strictly convex problems, where the minimizer is unique. A semidefinite or indefinite H is refused with that reason when the model is built. - Inequality Matrix A – the inequality matrix, [p,n], or [] for none. Its right-hand side is the b port.
- Equality Matrix Aeq, Equality Vector beq – the equality constraints, [q,n] and [q,1], or [] for none. The rows of Aeq must be linearly independent. beq is a SETTING, not a port: only the inequality right-hand side moves per step.
- Lower Bounds lb, Upper Bounds ub – bounds, [n,1] each or [] for none; -Inf/Inf entries leave a variable unbounded on that side. Each finite bound becomes one more constraint row, and Aeq, A and the finite bounds together may not exceed 40 rows.
- Constraint Tolerance – a constraint counts as violated when it is breached by
more than this. Default 1e-8,
quadprog's own. - Maximum Iterations – the limit on solver passes, each one a small linear solve.
0 selects
quadprog's active-set default, 10·(variables + constraints). When the limit is reached the exit flag is 0 and x is the last iterate, which satisfies the constraints the solver had made active but may violate others. - Sampling Time (s) – zero or less inherits the solver's rate; a positive value runs the block at that period.
Code export
All ten targets: Python, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog and PLC Structured Text, printed from the same program the block runs, so every target does the same arithmetic in the same order as the simulation. H, the constraint rows, H−1 and H−1 times the constraint normals are baked in as constants at export time; re-export after changing them.
The whole solve runs in every generated body, and its cost is bounded: at most Maximum Iterations passes, each a Cholesky of a K×K matrix in the active constraints, where K is the number of constraint rows. That loop is that length in the emitted code and exits early through a flag.
The three HDL targets carry the arithmetic in real and quantize only at the
ports: simulation-only, not offered as synthesizable. A Cholesky has a division by a pivot
and a square root, and the active set is a data-dependent branch, none of which belongs in a
Q16.16 datapath.
Simulink bridge
None (Support::None). quadprog is an Optimization Toolbox
function and that toolbox ships no Simulink library at all, so there is no path a diagram could
name. The bridge reports this block rather than dropping it silently, and it has no parity
testbench; code export verification covers all ten languages.
Notes
- Algebraic: the answer depends on this step's f and b alone, and nothing is carried between steps – there is no warm start. It is piecewise affine in (f, b) rather than linear, so it carries no state space.
- ⚠ x is continuous in f and b while the exit flag is 1, which is why quantizing the two ports (as the HDL targets do) moves x smoothly rather than jumping. The flag itself is a discrete output: a problem sitting on the feasibility boundary, or on the iteration limit, can be flagged differently by a target that sees a quantized right-hand side.
- ⚠ An exit flag of −2 or 0 leaves x defined but not optimal: it is the iterate the solver had reached, which satisfies the constraints it had made active and may violate the rest. MATLAB's own x is different there, because a different method walks a different path.
- beq is not a port and neither are the bounds, by design: only the right-hand side b moves per step. A model whose equalities move with the state needs those equalities eliminated first – which is exactly what condensing an MPC problem does.
- The measured agreement with R2026a, the problem sets behind it and the emitted MATLAB body's own check are on the source banner.
Code facts#
| Fact | Value |
|---|---|
| registered type | Control_Systems/Optimization/Quadratic_Program |
| family | Control_Systems/Optimization |
| solver environment class | ICoreBlock_0_Control_Systems_1_Optimization_2_Quadratic_Program |
| source | src/ICoreBlocks/ICoreBlockLibrary/Blocks/Control_Systems/Optimization/Quadratic_Program/ICoreBlock_0_Control_Systems_1_Optimization_2_Quadratic_Program.cpp |
| header | src/ICoreBlocks/ICoreBlockLibrary/Blocks/Control_Systems/Optimization/Quadratic_Program/ICoreBlock_0_Control_Systems_1_Optimization_2_Quadratic_Program.h |
| default size on canvas | 170 × 100 px |
| ports at insert | 2 in, 3 out |
| code generators implemented | Python, MATLAB, Java, Rust, C, C++, VHDL, Verilog, SystemVerilog, PLC Structured Text |
Ports#
| # | Direction | Signal type | Description label |
|---|---|---|---|
| 1 | in | ICoreDouble | f |
| 2 | in | ICoreDouble | b |
| 3 | out | ICoreDouble | x |
| 4 | out | ICoreDouble | fval |
| 5 | out | ICoreDouble | exitflag |
Ports the constructor creates. A block whose port list changes with its configuration adds or removes ports at load time; the count above is the one a freshly inserted block has.
Configuration variables#
| Config variable | Default | Simulink parameter |
|---|---|---|
Hessian Matrix H | [2 0.5 0; 0.5 1.5 0.3; 0 0.3 1] | — |
Inequality Matrix A | [1 0.5 0.2; 0.3 1 0.4; 0.6 0.2 1] | — |
Equality Matrix Aeq | [] | — |
Equality Vector beq | [] | — |
Lower Bounds lb | [] | — |
Upper Bounds ub | [] | — |
Constraint Tolerance | 1e-8 | — |
Maximum Iterations | 0 | — |
Options | — | — |
Every block also carries Sampling Time (s) from ICoreBlockSolverEnvironment: zero or less inherits the solver's rate, a positive value runs the block at that period.
Simulink bridge#
| support | Support::None |
| Simulink path | — |
| port-count rule | PortsParam::None |
SampleTime parameter | yes |
Caveat (shown to the user): quadprog is an Optimization Toolbox function and that toolbox ships no Simulink library, so there is no path a diagram could name; the block is reported rather than dropped when a model crosses
Catalog contract: src/ICoreBlocks/ICoreCoder/ICoreCommandSystem/SimulinkBridge/ICoreSimulinkBlockCatalog.h
Description vs code#
The lists agree. check_block_descriptions.py finds no disagreement between the description's Ports, Parameters, Code export and Simulink bridge lists and the code's.
The verdict above is
tools/docs/check_block_descriptions.py(P7.1), which compares LISTS. It cannot read a sentence: "stateless" on a block with a state, an initial-value semantic the recursion does not implement, a "not synthesizable" caveat the HDL banner contradicts. That is the agent audit (P7.3) on BLOCK_DESCRIPTION_AUDIT.md, and this tool's green is not a substitute for one.
File banner (developer view)#
The top comment of the block's .cpp — the maths, the realization and the export strategy, addressed to whoever changes it. It must not contradict the description above (P7.5).
Quadratic Program -- MATLAB's quadprog, on every step minimize 1/2 x'Hx + f'x subject to Aeq x = beq, A x <= b, lb <= x <= ub
The solver is the Goldfarb-Idnani DUAL active set (ICoreOptimizationSupport): it starts from the unconstrained minimizer x = -H^-1 f, adds the most violated constraint, and drops the active constraint whose multiplier would turn negative first. Every pass solves one small system; there is no phase one, and infeasibility is what the method reports when a violated constraint cannot be added at any step length.
H, A, Aeq, beq, lb and ub are SETTINGS and f and b arrive on PORTS. That split is the one a model-predictive controller wants: the condensed MPC Hessian and constraint matrix are fixed by the horizon and the model, while the linear term and the right-hand side are recomputed from the state at every step. It is also what makes the per-step cost bounded: H^-1, the constraint normals and H^-1 times them are computed once, at config load, and printed into every export as literals.
Measured against R2026a over 2200 problems (n <= 12, up to 40 constraint rows, equalities, bounds with infinite entries, duplicated rows, constraints through the unconstrained optimum, degenerate vertices and 582 infeasible ones): every exit flag equal, and where both converged worst |dx|/(1+|x|) = 4.2e-11 against quadprog's own 'active-set' algorithm (1.6e-6 against the default interior point, which is that solver's own accuracy). The emitted MATLAB body, run in R2026a, is bit-identical to this C++ and agrees with quadprog to 4.2e-14.
Support::None: quadprog is an Optimization Toolbox function and that toolbox ships no Simulink library, so there is no path a diagram could name.
Sample results#
Plotted: vector — Sine Wave, [3,1]: amplitudes 1/2/3 at 2 rad/s (tried only because every scalar stimulus was refused)
Category dynamic · sample time 0.1 · 60 steps · commit 6e86c1ef7f9cbef66d471271096a3bb1dc78e0c1 · produced by docsSample --out <folder> --blocks Nonnegative_Least_Squares Quadratic_Program Constrained_Linear_Least_Squares --steps 60 · data docs/generated/samples/Control_Systems__Optimization__Quadratic_Program.json · the SVG is generated from those numbers by tools/docs/plot_svg.py, so it is a run and not a drawing (R-D10).