Linear Algebra
8.410 min read

Quadratic Functions

A quadratic function on Rn\mathbb{R}^n has every term of degree exactly two. That means terms like xi2x_i^2 (a variable squared) or xixjx_i x_j (a product of two different variables). The general quadratic function can be written using a matrix: f(x)=xAxf(\mathbf{x}) = \mathbf{x}^\top A \mathbf{x} where AA is an n×nn \times n matrix.

Expanding the matrix product: xAx=i=1nj=1naijxixj\mathbf{x}^\top A \mathbf{x} = \sum_{i=1}^n \sum_{j=1}^n a_{ij} x_i x_j. The diagonal terms aiixi2a_{ii} x_i^2 contribute the squared terms, while the off-diagonal terms aijxixja_{ij} x_i x_j (for iji \neq j) contribute the cross terms. For example, if n=2n=2: xAx=a11x12+a12x1x2+a21x2x1+a22x22.\mathbf{x}^\top A \mathbf{x} = a_{11}x_1^2 + a_{12}x_1 x_2 + a_{21}x_2 x_1 + a_{22}x_2^2.

A general second-degree function includes a quadratic part, a linear part, and a constant: f(x)=xAx+bx+cf(\mathbf{x}) = \mathbf{x}^\top A \mathbf{x} + \mathbf{b}^\top \mathbf{x} + c. This is the most general polynomial of degree 2\leq 2 on Rn\mathbb{R}^n.

Formal View

Definition 8.4 — Quadratic Function (Quadratic Form)
A quadratic function on Rn\mathbb{R}^n is a function of the form f(x)=xAxf(\mathbf{x}) = \mathbf{x}^\top A \mathbf{x} for an n×nn \times n matrix AA. Every term has total degree exactly 2. A general second-degree function is f(x)=xAx+bx+cf(\mathbf{x}) = \mathbf{x}^\top A \mathbf{x} + \mathbf{b}^\top \mathbf{x} + c.

Example: f(x1,x2,x3)=3x12+7x22+x32+2x1x2+4x3x1f(x_1, x_2, x_3) = 3x_1^2 + 7x_2^2 + x_3^2 + 2x_1 x_2 + 4x_3 x_1 is a quadratic form in three variables.

Why This Matters

Quadratic functions are the simplest non-trivial functions to optimize — they appear everywhere energy, error, or curvature is measured.

  • Least-squares regression: Axb2=xAAx2bAx+b2\|A\mathbf{x} - \mathbf{b}\|^2 = \mathbf{x}^\top A^\top A \mathbf{x} - 2\mathbf{b}^\top A \mathbf{x} + \|\mathbf{b}\|^2 is a quadratic function of x\mathbf{x}.
  • Elastic potential energy: U=12xKxU = \frac{1}{2}\mathbf{x}^\top K \mathbf{x} where KK is the stiffness matrix.
  • Portfolio variance: σ2=wΣw\sigma^2 = \mathbf{w}^\top \Sigma \mathbf{w} is a quadratic function of portfolio weights.

Quiz

Question 1

For the quadratic form f(x1,x2)=xAxf(x_1, x_2) = \mathbf{x}^\top A \mathbf{x} with A=(1234)A = \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}, what is f(1,1)f(1, 1)?

Question 2

The function f(x1,x2)=x12+3x1x2+x22f(x_1, x_2) = x_1^2 + 3x_1 x_2 + x_2^2 is a pure quadratic form (no linear or constant terms).

Common Mistakes

  • Forgetting that xAx\mathbf{x}^\top A \mathbf{x} sums over ALL pairs (i,j)(i,j), including both aijxixja_{ij} x_i x_j and ajixjxia_{ji} x_j x_i when iji \neq j.
  • Confusing a quadratic function f(x)f(\mathbf{x}) with a quadratic equation f(x)=0f(\mathbf{x}) = 0 — the function itself is not an equation.