# Quadratic constraints in JuMP

I am a bit new to programming and am currently working with solving optimization problems in JuMP in Julia.

I got a tip from the JuMP page that I should also use @constraint if a term is quadratic. However, how do I know if a constraint is quadratic?

For instance, should I use @constraint or @NLconstraint for $$z - 2 + 4 z y = 0$$ and $$x - z^2 \geq 0$$?

All I know is that it should have the form $$\frac{1}2 x H x + q x$$ where $$x$$ is the vector with all the variables.

• 1/2 x * H * x is just a fancy way to write $\sum_{j_1} \sum_{j_2} h_{j_1,j_2} x_{j_1} x_{j_2}$ Sep 23, 2022 at 13:48
• If you're looking for solvers, note that quadratic constraints mean that your model is not a quadratic programming problem. You need a QPQC solver, or nonlinear programming solver Sep 23, 2022 at 15:41

A "quadratic constraint" is a constraint of the form $$f(x) \leq 0$$, where $$f(x)$$ is a quadratic function, i.e., as you wrote, $$f(x) = \frac{1}{2}x^{T}Hx + q^{T}x + b$$ for some square matrix $$H \in \mathbb{R}^{n \times n}$$, vector $$q \in \mathbb{R}^{n}$$, and some scalar $$b \in \mathbb{R}$$.
In JuMP, you can declare such quadratic constraints with the @constraint syntax directly. The @NLconstraint macro is designed for more general nonlinear that require special handling of function evaluation and derivatives. For instance, if your constraints have high-order polynomial functions ($$x^{3}$$ and above), or terms like sin, cos, log or exp, you should use @NLconstraint.
• You can build higher order polynomials via quadratic constraints though or use PolyJuMP compared to the general purpose @NLConstraints. This can be useful to make some solvers like Gurobi solve problems they won't otherwise as @NLConstraints is not supported by some, however quadratic terms are. Sep 22, 2022 at 15:57