Expressions like 5x12−4x1x2+5x22 appear whenever you measure energy, variance, or curvature. The cross term −4x1x2 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 is a function of the form
Q(x)=xTAx,
where A is an n×nsymmetric matrix, called the matrix of the quadratic form.
So every term has degree exactly 2. The diagonal entries of A 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 xixj (with i=j) is 2aij.
Worked example: Finding the matrix
Find the matrix of Q(x)=x12+2x22−3x32+4x1x2−6x2x3, then compute Q(1,−1,2).
The squares give the diagonal 1,2,−3. The x1x2 coefficient 4 splits into 2 and 2; the x2x3 coefficient −6 splits into −3 and −3; there is no x1x3 term, so those entries are 0:
A=12022−30−3−3.
Directly: Q(1,−1,2)=1+2−12−4+12=−1. With the matrix: A(1,−1,2)=(−1,−6,−3), and (1,−1,2)⋅(−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 6x1x2, the entries a12 and a21 are each 3, not 6.
Removing the cross terms
Because A is symmetric, the spectral theorem gives A=PDPT with P orthogonal. Make the change of variable
If A is symmetric, the orthogonal change of variable x=Py, where the columns of P are an orthonormal eigenbasis of A, turns xTAx into
λ1y12+⋯+λnyn2,
a quadratic form with no cross terms. The columns of P are called the principal axes of the form.
Since P 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+5x22 and describe the curve Q(x)=21.
The matrix is A=[5−2−25], with characteristic polynomial λ2−10λ+21=(λ−3)(λ−7).
For λ=3: A−3I=[2−2−22], so u1=21(1,1). For λ=7: u2=21(1,−1).
With x=Py and P=[u1u2], the form becomes 3y12+7y22. The curve 3y12+7y22=21 is
7y12+3y22=1,
an ellipse with semi-axis 7≈2.65 along the line y=x (direction u1) and semi-axis 3≈1.73 along the line y=−x (direction u2).
The ellipse 5x² − 4xy + 5y² = 21 with its principal axesOpen in grapher →
Notice that the smaller eigenvalue goes with the longer axis: along u1 the form grows slowly, so you have to travel farther to reach the level 21.
Classifying quadratic forms
The diagonal form λ1y12+⋯+λnyn2 makes the sign of Q obvious.
Definition
Definiteness
A quadratic form Q (and its symmetric matrix A) is
positive definite if Q(x)>0 for every x=0; this happens exactly when all eigenvalues of A are positive;
negative definite if Q(x)<0 for every x=0; exactly when all eigenvalues are negative;
indefinite if Q takes both positive and negative values; exactly when A has both a positive and a negative eigenvalue.
If all eigenvalues are ≥0 (some equal to 0) the form is positive semidefinite, and if all are ≤0 it is negative semidefinite.
Worked example: An indefinite form
Classify Q(x)=x12+6x1x2+x22.
The matrix [1331] has characteristic polynomial λ2−2λ−8=(λ−4)(λ+2). One eigenvalue is positive and one is negative, so Q is indefinite. You can confirm with two inputs: Q(1,1)=8>0 but Q(1,−1)=−4<0. The level curves of Q are hyperbolas, not ellipses.
Tip
For a 2×2 matrix [abbc] you don't need the eigenvalues. Since detA=λ1λ2 and trA=λ1+λ2: if detA<0 the form is indefinite; if detA>0 and a>0 it is positive definite; if detA>0 and a<0 it is negative definite.
Maximizing a quadratic form on the unit sphere
A classic question: over all unit vectors x, how large and how small can Q(x)=xTAx be? Change variables to x=Py. Since P is orthogonal, ∥y∥=∥x∥=1. If the eigenvalues are ordered λ1≥λ2≥⋯≥λn, then
λ1y12+⋯+λnyn2≤λ1(y12+⋯+yn2)=λ1,
with equality when y=(1,0,…,0), that is, when x=u1. The same argument works for the minimum.
Constrained extremes
Let A be symmetric with largest eigenvalue λmax and smallest eigenvalue λmin. Subject to ∥x∥=1,
the maximum of xTAx is λmax, reached at a unit eigenvector for λmax;
the minimum of xTAx is λmin, reached at a unit eigenvector for λmin.
Worked example: Extremes in three variables
Find the maximum and minimum of Q(x)=4x12+4x22+x32+2x1x2 subject to x12+x22+x32=1, and where they occur.
The matrix is A=410140001. The upper-left block [4114] has eigenvalues 5 (eigenvector (1,1)) and 3 (eigenvector (1,−1)), and the last diagonal entry contributes the eigenvalue 1 with eigenvector (0,0,1).
So the maximum is 5, at x=±21(1,1,0), and the minimum is 1, at x=±(0,0,1). Check the maximum: Q(21,21,0)=2+2+0+1=5.
Practice
Practice 1
Let A be the matrix of the quadratic form Q(x)=2x12+6x1x2−x22. Find the (1,2) entry of A.
Enter a number. Fractions like 3/4 and sqrt(2) are OK.
Practice 2
Let A=[2−1−13] and x=(2,1). Compute xTAx.
Enter a number. Fractions like 3/4 and sqrt(2) are OK.
Practice 3
Classify Q(x)=3x12+4x1x2+3x22.
Practice 4
An orthogonal change of variable x=Py turns Q(x)=x12−8x1x2−5x22 into λ1y12+λ2y22. Find λ1 and λ2.
Separate answers with commas, e.g. 2, -5
Practice 5
Find the maximum value of Q(x)=7x12+4x1x2+4x22 subject to x12+x22=1.
Enter a number. Fractions like 3/4 and sqrt(2) are OK.
Practice 6
For which values of k is Q(x)=x12+2kx1x2+4x22 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−2x1x2 subject to ∥x∥=1.
Enter a number. Fractions like 3/4 and sqrt(2) are OK.
Practice 8
The curve 6x2+4xy+3y2=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.