Skip to content
Glacius
CalculusConcept reference

Quadratic-Form Gradients

In q(x)=x^TAx, the input vector occurs on both sides of the fixed matrix.

On this page 7 sections
  1. Overview
  2. The variable occurs twice
  3. Use a nonsymmetric matrix
  4. When the shorter rule works
  5. Key takeaway
  6. Sources & further reading
  7. Concept connections

01The variable occurs twice#

In q(x)=xTAxq(x)=x^TAx, the input vector occurs on both sides of the fixed matrix. Changing one coordinate can affect terms through either occurrence. The gradient must include both contributions.

Write q(x)=ijxiAijxjq(x)=\sum_i\sum_j x_iA_{ij}x_j. Differentiating with respect to xkx_k collects the terms where i=ki=k and those where j=kj=k:

qxk=jAkjxj+iAikxi\begin{gathered}\frac{\partial q}{\partial x_k}\\=\sum_j A_{kj}x_j\\+\sum_i A_{ik}x_i\end{gathered}

Those sums are the kkth entries of AxAx and ATxA^Tx.

q(x)=(A+AT)x.\nabla q(x)=(A+A^T)x.

02Use a nonsymmetric matrix#

Let AA have rows (1,2),(0,3)(1,2),(0,3) and x=(2,1)x=(2,1). Then Ax=(4,3)Ax=(4,3) and ATx=(2,7)A^Tx=(2,7). Adding gives the gradient (6,10)(6,10).

Expanding gives q(x)=x12+2x1x2+3x22q(x)=x_1^2+2x_1x_2+3x_2^2. Its partial derivatives are 2x1+2x22x_1+2x_2 and 2x1+6x22x_1+6x_2, again giving (6,10)(6,10) at (2,1)(2,1).

Check your reasoning

A has rows (1,2),(0,3); x=(1,1). Find ∇(xᵀAx).

  1. A(4,8)
  2. B(6,6)
  3. C(3,3)
Show answer and explanation
(4,8)

A+Aᵀ has rows (2,2),(2,6); multiply by x.

03When the shorter rule works#

If A=ATA=A^T, the two contributions match and the gradient becomes 2Ax2Ax. Without symmetry, that shortcut can fail: in the worked example 2Ax=(8,6)2Ax=(8,6), which is incorrect.

Check your reasoning

For symmetric A, what is the gradient of xᵀAx/2?

  1. A2Ax
  2. BAx
  3. CAᵀx/2
Show answer and explanation
Ax

The factor one-half cancels the factor two.

A leading factor of one-half halves the gradient. Keep the fixed matrix and the differentiating variable explicit. This lesson computes the gradient; deciding whether the quadratic has a minimum requires additional structure.

Key takeaway

Compute the gradient of xᵀAx as (A + Aᵀ)x for a constant real square matrix A.

  • Compute the gradient of xᵀAx as (A + Aᵀ)x for a constant real square matrix A.

Sources & further reading

  1. [1]
  2. [2]

Reference this concept

Link to this page, a section, or an individual figure.

Glacius. “Quadratic-Form Gradients.” Math behind ML. /learn/c-quadratic-gradient