Math Core

Lesson 7.2 · Symmetric Matrices

Quadratic forms

Expressions like 5x12−4x1x2+5x225x_1^2 - 4x_1x_2 + 5x_2^2 appear whenever you measure energy, variance, or curvature. The cross term −4x1x2-4x_1x_2 makes them hard to read: is the expression always positive? What shape is its level curve? Writing the expression with a symmetric matrix and applying the spectral theorem removes the cross terms and answers these questions at once.

Quadratic forms and their matrices

Definition

Quadratic form

A quadratic form on Rn\mathbb{R}^n is a function of the form

Q(x)=xTAx,Q(\mathbf{x}) = \mathbf{x}^TA\mathbf{x},

where AA is an n×nn \times n symmetric matrix, called the matrix of the quadratic form.

Multiply it out for n=2n = 2 with A=[abbc]A = \begin{bmatrix} a & b \\ b & c \end{bmatrix}:

xTAx=[x1x2][ax1+bx2bx1+cx2]=ax12+2bx1x2+cx22.\mathbf{x}^TA\mathbf{x} = \begin{bmatrix} x_1 & x_2 \end{bmatrix}\begin{bmatrix} ax_1 + bx_2 \\ bx_1 + cx_2 \end{bmatrix} = ax_1^2 + 2bx_1x_2 + cx_2^2.

So every term has degree exactly 22. The diagonal entries of AA are the coefficients of the squares, and each cross-term coefficient is split in half between the two symmetric off-diagonal positions. The same rule holds in any dimension: the coefficient of xixjx_ix_j (with i≠ji \ne j) is 2aij2a_{ij}.

Worked example: Finding the matrix

Find the matrix of Q(x)=x12+2x22−3x32+4x1x2−6x2x3Q(\mathbf{x}) = x_1^2 + 2x_2^2 - 3x_3^2 + 4x_1x_2 - 6x_2x_3, then compute Q(1,−1,2)Q(1, -1, 2).

The squares give the diagonal 1,2,−31, 2, -3. The x1x2x_1x_2 coefficient 44 splits into 22 and 22; the x2x3x_2x_3 coefficient −6-6 splits into −3-3 and −3-3; there is no x1x3x_1x_3 term, so those entries are 00:

A=[12022−30−3−3].A = \begin{bmatrix} 1 & 2 & 0 \\ 2 & 2 & -3 \\ 0 & -3 & -3 \end{bmatrix}.

Directly: Q(1,−1,2)=1+2−12−4+12=−1Q(1, -1, 2) = 1 + 2 - 12 - 4 + 12 = -1. With the matrix: A(1,−1,2)=(−1,−6,−3)A(1, -1, 2) = (-1, -6, -3), and (1,−1,2)⋅(−1,−6,−3)=−1+6−6=−1(1, -1, 2) \cdot (-1, -6, -3) = -1 + 6 - 6 = -1.

Common mistake

The most common mistake is putting the whole cross-term coefficient in one off-diagonal spot, or putting it in both. For 6x1x26x_1x_2, the entries a12a_{12} and a21a_{21} are each 33, not 66.

Removing the cross terms

Because AA is symmetric, the spectral theorem gives A=PDPTA = PDP^T with PP orthogonal. Make the change of variable

x=Py,equivalentlyy=PTx.\mathbf{x} = P\mathbf{y}, \qquad \text{equivalently} \qquad \mathbf{y} = P^T\mathbf{x}.

Then

xTAx=(Py)TA(Py)=yT(PTAP)y=yTDy=λ1y12+λ2y22+⋯+λnyn2.\mathbf{x}^TA\mathbf{x} = (P\mathbf{y})^TA(P\mathbf{y}) = \mathbf{y}^T(P^TAP)\mathbf{y} = \mathbf{y}^TD\mathbf{y} = \lambda_1y_1^2 + \lambda_2y_2^2 + \cdots + \lambda_ny_n^2.

The principal axes theorem

If AA is symmetric, the orthogonal change of variable x=Py\mathbf{x} = P\mathbf{y}, where the columns of PP are an orthonormal eigenbasis of AA, turns xTAx\mathbf{x}^TA\mathbf{x} into

λ1y12+⋯+λnyn2,\lambda_1y_1^2 + \cdots + \lambda_ny_n^2,

a quadratic form with no cross terms. The columns of PP are called the principal axes of the form.

Since PP is orthogonal, the change of variable is just a rotation (possibly with a reflection) of the coordinate axes. Lengths and angles don't change; you are simply looking at the same form along better axes.

Worked example: A tilted ellipse

Remove the cross term from Q(x)=5x12−4x1x2+5x22Q(\mathbf{x}) = 5x_1^2 - 4x_1x_2 + 5x_2^2 and describe the curve Q(x)=21Q(\mathbf{x}) = 21.

The matrix is A=[5−2−25]A = \begin{bmatrix} 5 & -2 \\ -2 & 5 \end{bmatrix}, with characteristic polynomial λ2−10λ+21=(λ−3)(λ−7)\lambda^2 - 10\lambda + 21 = (\lambda - 3)(\lambda - 7).

For λ=3\lambda = 3: A−3I=[2−2−22]A - 3I = \begin{bmatrix} 2 & -2 \\ -2 & 2 \end{bmatrix}, so u1=12(1,1)\mathbf{u}_1 = \frac{1}{\sqrt{2}}(1, 1). For λ=7\lambda = 7: u2=12(1,−1)\mathbf{u}_2 = \frac{1}{\sqrt{2}}(1, -1).

With x=Py\mathbf{x} = P\mathbf{y} and P=[u1u2]P = \begin{bmatrix} \mathbf{u}_1 & \mathbf{u}_2 \end{bmatrix}, the form becomes 3y12+7y223y_1^2 + 7y_2^2. The curve 3y12+7y22=213y_1^2 + 7y_2^2 = 21 is

y127+y223=1,\frac{y_1^2}{7} + \frac{y_2^2}{3} = 1,

an ellipse with semi-axis 7≈2.65\sqrt{7} \approx 2.65 along the line y=xy = x (direction u1\mathbf{u}_1) and semi-axis 3≈1.73\sqrt{3} \approx 1.73 along the line y=−xy = -x (direction u2\mathbf{u}_2).

The ellipse 5x² − 4xy + 5y² = 21 with its principal axesOpen in grapher →

Notice that the smaller eigenvalue goes with the longer axis: along u1\mathbf{u}_1 the form grows slowly, so you have to travel farther to reach the level 2121.

Classifying quadratic forms

The diagonal form λ1y12+⋯+λnyn2\lambda_1y_1^2 + \cdots + \lambda_ny_n^2 makes the sign of QQ obvious.

Definition

Definiteness

A quadratic form QQ (and its symmetric matrix AA) is

  • positive definite if Q(x)>0Q(\mathbf{x}) > 0 for every x≠0\mathbf{x} \ne \mathbf{0}; this happens exactly when all eigenvalues of AA are positive;
  • negative definite if Q(x)<0Q(\mathbf{x}) < 0 for every x≠0\mathbf{x} \ne \mathbf{0}; exactly when all eigenvalues are negative;
  • indefinite if QQ takes both positive and negative values; exactly when AA has both a positive and a negative eigenvalue.

If all eigenvalues are ≥0\ge 0 (some equal to 00) the form is positive semidefinite, and if all are ≤0\le 0 it is negative semidefinite.

Worked example: An indefinite form

Classify Q(x)=x12+6x1x2+x22Q(\mathbf{x}) = x_1^2 + 6x_1x_2 + x_2^2.

The matrix [1331]\begin{bmatrix} 1 & 3 \\ 3 & 1 \end{bmatrix} has characteristic polynomial λ2−2λ−8=(λ−4)(λ+2)\lambda^2 - 2\lambda - 8 = (\lambda - 4)(\lambda + 2). One eigenvalue is positive and one is negative, so QQ is indefinite. You can confirm with two inputs: Q(1,1)=8>0Q(1, 1) = 8 > 0 but Q(1,−1)=−4<0Q(1, -1) = -4 < 0. The level curves of QQ are hyperbolas, not ellipses.

Tip

For a 2×22 \times 2 matrix [abbc]\begin{bmatrix} a & b \\ b & c \end{bmatrix} you don't need the eigenvalues. Since det⁡A=λ1λ2\det A = \lambda_1\lambda_2 and tr⁡A=λ1+λ2\operatorname{tr}A = \lambda_1 + \lambda_2: if det⁡A<0\det A < 0 the form is indefinite; if det⁡A>0\det A > 0 and a>0a > 0 it is positive definite; if det⁡A>0\det A > 0 and a<0a < 0 it is negative definite.

Maximizing a quadratic form on the unit sphere

A classic question: over all unit vectors x\mathbf{x}, how large and how small can Q(x)=xTAxQ(\mathbf{x}) = \mathbf{x}^TA\mathbf{x} be? Change variables to x=Py\mathbf{x} = P\mathbf{y}. Since PP is orthogonal, ∥y∥=∥x∥=1\|\mathbf{y}\| = \|\mathbf{x}\| = 1. If the eigenvalues are ordered λ1≥λ2≥⋯≥λn\lambda_1 \ge \lambda_2 \ge \cdots \ge \lambda_n, then

λ1y12+⋯+λnyn2≤λ1(y12+⋯+yn2)=λ1,\lambda_1y_1^2 + \cdots + \lambda_ny_n^2 \le \lambda_1(y_1^2 + \cdots + y_n^2) = \lambda_1,

with equality when y=(1,0,…,0)\mathbf{y} = (1, 0, \ldots, 0), that is, when x=u1\mathbf{x} = \mathbf{u}_1. The same argument works for the minimum.

Constrained extremes

Let AA be symmetric with largest eigenvalue λmax⁡\lambda_{\max} and smallest eigenvalue λmin⁡\lambda_{\min}. Subject to ∥x∥=1\|\mathbf{x}\| = 1,

  • the maximum of xTAx\mathbf{x}^TA\mathbf{x} is λmax⁡\lambda_{\max}, reached at a unit eigenvector for λmax⁡\lambda_{\max};
  • the minimum of xTAx\mathbf{x}^TA\mathbf{x} is λmin⁡\lambda_{\min}, reached at a unit eigenvector for λmin⁡\lambda_{\min}.

Worked example: Extremes in three variables

Find the maximum and minimum of Q(x)=4x12+4x22+x32+2x1x2Q(\mathbf{x}) = 4x_1^2 + 4x_2^2 + x_3^2 + 2x_1x_2 subject to x12+x22+x32=1x_1^2 + x_2^2 + x_3^2 = 1, and where they occur.

The matrix is A=[410140001]A = \begin{bmatrix} 4 & 1 & 0 \\ 1 & 4 & 0 \\ 0 & 0 & 1 \end{bmatrix}. The upper-left block [4114]\begin{bmatrix} 4 & 1 \\ 1 & 4 \end{bmatrix} has eigenvalues 55 (eigenvector (1,1)(1, 1)) and 33 (eigenvector (1,−1)(1, -1)), and the last diagonal entry contributes the eigenvalue 11 with eigenvector (0,0,1)(0, 0, 1).

So the maximum is 55, at x=±12(1,1,0)\mathbf{x} = \pm\frac{1}{\sqrt{2}}(1, 1, 0), and the minimum is 11, at x=±(0,0,1)\mathbf{x} = \pm(0, 0, 1). Check the maximum: Q(12,12,0)=2+2+0+1=5Q\left(\tfrac{1}{\sqrt{2}}, \tfrac{1}{\sqrt{2}}, 0\right) = 2 + 2 + 0 + 1 = 5.

Practice

Practice 1

Let AA be the matrix of the quadratic form Q(x)=2x12+6x1x2−x22Q(\mathbf{x}) = 2x_1^2 + 6x_1x_2 - x_2^2. Find the (1,2)(1, 2) entry of AA.

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 2

Let A=[2−1−13]A = \begin{bmatrix} 2 & -1 \\ -1 & 3 \end{bmatrix} and x=(2,1)\mathbf{x} = (2, 1). Compute xTAx\mathbf{x}^TA\mathbf{x}.

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 3

Classify Q(x)=3x12+4x1x2+3x22Q(\mathbf{x}) = 3x_1^2 + 4x_1x_2 + 3x_2^2.

Practice 4

An orthogonal change of variable x=Py\mathbf{x} = P\mathbf{y} turns Q(x)=x12−8x1x2−5x22Q(\mathbf{x}) = x_1^2 - 8x_1x_2 - 5x_2^2 into λ1y12+λ2y22\lambda_1y_1^2 + \lambda_2y_2^2. Find λ1\lambda_1 and λ2\lambda_2.

Separate answers with commas, e.g. 2, -5

Practice 5

Find the maximum value of Q(x)=7x12+4x1x2+4x22Q(\mathbf{x}) = 7x_1^2 + 4x_1x_2 + 4x_2^2 subject to x12+x22=1x_1^2 + x_2^2 = 1.

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 6

For which values of kk is Q(x)=x12+2kx1x2+4x22Q(\mathbf{x}) = x_1^2 + 2kx_1x_2 + 4x_2^2 positive definite?

Enter an inequality, e.g. x >= 4, -2 < x <= 3, or x < 1 or x > 5

Practice 7

Find the minimum value of Q(x)=2x12+2x22+5x32−2x1x2Q(\mathbf{x}) = 2x_1^2 + 2x_2^2 + 5x_3^2 - 2x_1x_2 subject to ∥x∥=1\|\mathbf{x}\| = 1.

Enter a number. Fractions like 3/4 and sqrt(2) are OK.

Practice 8

The curve 6x2+4xy+3y2=146x^2 + 4xy + 3y^2 = 14 is an ellipse. Find the length of its semi-major axis (half the longest diameter).

Enter a number. Fractions like 3/4 and sqrt(2) are OK.