Unit 9, lesson 45

Quadratic Forms and Positive Definiteness

How a quadratic form is written with a symmetric matrix, why cross terms split in half, how principal axes remove them, and how eigenvalue signs make a form definite, semidefinite or indefinite.

  • Video 45
  • The Spectral Theorem and Quadratic Forms

The curve 5x2+4xy+2y2=15x^2 + 4xy + 2y^2 = 1 is an ellipse, but its axes are tilted, and the term 4xy4xy hides which way they point. Changing to perpendicular coordinates along the eigenvectors of its symmetric matrix removes that term and leaves a weighted sum of squares. The signs of the weights then settle a question that the signs of the entries cannot, namely whether the expression is positive for every nonzero input. This lesson writes quadratic forms with symmetric matrices, explains the factor 22 in a cross term, and classifies forms as definite, semidefinite or indefinite by the signs of their eigenvalues. Tuples such as (x,y)(x, y) stand for column vectors.

Key terms

Quadratic form

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

q(x)=x⊤Ax=∑i=1n∑j=1naijxixj\begin{aligned} q(\mathbf{x}) &= \mathbf{x}^{\top}A\mathbf{x} \\[0.4em] &= \sum_{i=1}^{n}\sum_{j=1}^{n} a_{ij}x_i x_j \end{aligned}

for some real n×nn \times n matrix AA. The product AxA\mathbf{x} is a vector, and its dot product with x\mathbf{x} is a single number, so qq assigns a scalar to each vector, unlike the linear map x↦Ax\mathbf{x} \mapsto A\mathbf{x}. Every term has degree exactly 22 in the entries of x\mathbf{x}, so q(cx)=c2q(x)q(c\mathbf{x}) = c^2 q(\mathbf{x}) for every real cc. In particular q(0)=0q(\mathbf{0}) = 0 and q(−x)=q(x)q(-\mathbf{x}) = q(\mathbf{x}). A quadratic form is generally not linear.

In plain words A quadratic form is a polynomial in the coordinates in which every term is a constant times the square of one coordinate or times the product of two. It takes a vector and returns one number.

Example With x=(x,y)\mathbf{x} = (x, y) and

A=[5222],A = \begin{bmatrix} 5 & 2 \\ 2 & 2 \end{bmatrix},

the product is Ax=(5x+2y,2x+2y)A\mathbf{x} = (5x + 2y, 2x + 2y), and its dot product with x\mathbf{x} is

q(x,y)=x(5x+2y)+y(2x+2y)=5x2+4xy+2y2.\begin{aligned} q(x, y) &= x(5x + 2y) \\[0.4em] &\quad + y(2x + 2y) \\[0.4em] &= 5x^2 + 4xy + 2y^2. \end{aligned}

Doubling the input multiplies the value by four, since q(1,1)=11q(1, 1) = 11 and q(2,2)=44q(2, 2) = 44. The form is not linear, because q(1,0)+q(0,1)=5+2=7q(1, 0) + q(0, 1) = 5 + 2 = 7 while q(1,1)=11q(1, 1) = 11.

Matrix of a quadratic form

Definition Every quadratic form can be written as q(x)=x⊤Axq(\mathbf{x}) = \mathbf{x}^{\top}A\mathbf{x} with AA symmetric, and this symmetric matrix is unique. It is called the matrix of the quadratic form. If q(x)=x⊤Mxq(\mathbf{x}) = \mathbf{x}^{\top}M\mathbf{x} for some real square matrix MM, split M=A+KM = A + K into its symmetric part A=12(M+M⊤)A = \frac{1}{2}(M + M^{\top}) and its skew-symmetric part K=12(M−M⊤)K = \frac{1}{2}(M - M^{\top}). The skew part contributes nothing, because the number x⊤Kx\mathbf{x}^{\top}K\mathbf{x} equals its own transpose x⊤K⊤x=−x⊤Kx\mathbf{x}^{\top}K^{\top}\mathbf{x} = -\mathbf{x}^{\top}K\mathbf{x} and is therefore 00. The symmetric matrix is unique because its entries are determined by values of qq, namely aii=q(ei)a_{ii} = q(\mathbf{e}_i) and, for i≠ji \ne j,

2aij=q(ei+ej)−q(ei)−q(ej).\begin{aligned} 2a_{ij} &= q(\mathbf{e}_i + \mathbf{e}_j) \\[0.4em] &\quad - q(\mathbf{e}_i) - q(\mathbf{e}_j). \end{aligned}

A cross term of qq is a term k xixjk\,x_i x_j with i≠ji \ne j. In the symmetric matrix its coefficient is split equally between two positions, aij=aji=k/2a_{ij} = a_{ji} = k/2, while the coefficient of xi2x_i^2 is aiia_{ii}. In two variables,

ax2+2bxy+cy2=[xy][abbc][xy].\begin{aligned} &ax^2 + 2bxy + cy^2 \\[0.4em] &= \begin{bmatrix} x & y \end{bmatrix}\begin{bmatrix} a & b \\ b & c \end{bmatrix}\begin{bmatrix} x \\ y \end{bmatrix}. \end{aligned}

In plain words The diagonal holds the coefficients of the squares. Each cross-term coefficient is cut in half and placed on both sides of the diagonal, because the product x⊤Ax\mathbf{x}^{\top}A\mathbf{x} picks up xixjx_i x_j once from aija_{ij} and once from ajia_{ji}.

Example The form q(x,y,z)=x2+3z2+6xy−4yzq(x, y, z) = x^2 + 3z^2 + 6xy - 4yz has the matrix

A=[13030−20−23].A = \begin{bmatrix} 1 & 3 & 0 \\ 3 & 0 & -2 \\ 0 & -2 & 3 \end{bmatrix}.

There is no y2y^2 term, so a22=0a_{22} = 0, and there is no xzxz term, so a13=a31=0a_{13} = a_{31} = 0. As a check, q(e1+e2)=1+0+6=7q(\mathbf{e}_1 + \mathbf{e}_2) = 1 + 0 + 6 = 7, and (7−1−0)/2=3=a12(7 - 1 - 0)/2 = 3 = a_{12}. The nonsymmetric matrix with rows (1,6)(1, 6) and (0,1)(0, 1) gives the same form x2+6xy+y2x^2 + 6xy + y^2 as its symmetric part, the matrix with rows (1,3)(1, 3) and (3,1)(3, 1). Copying the full coefficient into both places is a common mistake. The matrix with rows (1,6)(1, 6) and (6,1)(6, 1) gives x2+12xy+y2x^2 + 12xy + y^2, a different form.

Principal axes of a quadratic form

Definition Let q(x)=x⊤Axq(\mathbf{x}) = \mathbf{x}^{\top}A\mathbf{x} with AA real symmetric, and let A=QDQ⊤A = QDQ^{\top} be an orthogonal diagonalization with orthonormal eigenvectors q1,…,qn\mathbf{q}_1, \dots, \mathbf{q}_n and eigenvalues λ1,…,λn\lambda_1, \dots, \lambda_n. The lines through the origin spanned by q1,…,qn\mathbf{q}_1, \dots, \mathbf{q}_n are the principal axes of qq. When an eigenvalue is repeated, the axes inside its eigenspace can be chosen in many ways, and any orthonormal choice works. In the coordinates z=Q⊤x\mathbf{z} = Q^{\top}\mathbf{x} along these axes, so that x=Qz\mathbf{x} = Q\mathbf{z} and zi=qi⋅xz_i = \mathbf{q}_i \cdot \mathbf{x}, the form has no cross terms,

q(x)=z⊤Q⊤AQz=z⊤Dz=λ1z12+⋯+λnzn2.\begin{aligned} q(\mathbf{x}) &= \mathbf{z}^{\top}Q^{\top}AQ\mathbf{z} = \mathbf{z}^{\top}D\mathbf{z} \\[0.4em] &= \lambda_1 z_1^2 + \cdots + \lambda_n z_n^2. \end{aligned}

Because QQ is orthogonal, the new coordinates measure lengths and angles exactly as the old ones do, so a level set keeps its shape and size and is only described differently. When n=2n = 2 and λ1,λ2>0\lambda_1, \lambda_2 > 0, the level curve q=1q = 1 is an ellipse with semi-axes of length 1/λ11/\sqrt{\lambda_1} along q1\mathbf{q}_1 and 1/λ21/\sqrt{\lambda_2} along q2\mathbf{q}_2.

In plain words Measure along the eigenvector directions instead of along the standard axes. In those coordinates the form is a weighted sum of squares, and the weights are the eigenvalues.

Example For q=5x2+4xy+2y2q = 5x^2 + 4xy + 2y^2, the matrix AA from the first example has χA(t)=t2−7t+6=(t−6)(t−1)\chi_A(t) = t^2 - 7t + 6 = (t - 6)(t - 1), with eigenvectors (2,1)(2, 1) for 66 and (1,−2)(1, -2) for 11. These are perpendicular and have length 5\sqrt{5}, so the principal-axis coordinates are

z1=2x+y5,z2=x−2y5,\begin{aligned} z_1 &= \frac{2x + y}{\sqrt{5}}, \\[0.4em] z_2 &= \frac{x - 2y}{\sqrt{5}}, \end{aligned}

and q=6z12+z22q = 6z_1^2 + z_2^2. Expanding confirms this, since

65(2x+y)2+15(x−2y)2=15(25x2+20xy+10y2),\begin{aligned} &\tfrac{6}{5}(2x + y)^2 + \tfrac{1}{5}(x - 2y)^2 \\[0.4em] &\quad = \tfrac{1}{5}(25x^2 + 20xy + 10y^2), \end{aligned}

which is qq. The ellipse q=1q = 1 has semi-axis 1/61/\sqrt{6} along (2,1)(2, 1) and semi-axis 11 along (1,−2)(1, -2). For instance the unit vector 15(1,−2)\frac{1}{\sqrt{5}}(1, -2) gives q=(5−8+8)/5=1q = (5 - 8 + 8)/5 = 1.

Positive definite and negative definite

Definition A real symmetric n×nn \times n matrix AA, and its quadratic form q(x)=x⊤Axq(\mathbf{x}) = \mathbf{x}^{\top}A\mathbf{x}, are positive definite if q(x)>0q(\mathbf{x}) > 0 for every nonzero x\mathbf{x} in Rn\mathbb{R}^n, and negative definite if q(x)<0q(\mathbf{x}) < 0 for every nonzero x\mathbf{x}. The zero vector is excluded because q(0)=0q(\mathbf{0}) = 0 always. The eigenvalue test says that AA is positive definite if and only if all its eigenvalues are positive, and negative definite if and only if all its eigenvalues are negative. To prove the first statement, write q=λ1z12+⋯+λnzn2q = \lambda_1 z_1^2 + \cdots + \lambda_n z_n^2 with z=Q⊤x\mathbf{z} = Q^{\top}\mathbf{x}. Since QQ is invertible, x≠0\mathbf{x} \ne \mathbf{0} exactly when z≠0\mathbf{z} \ne \mathbf{0}. If every λi>0\lambda_i > 0, all terms are nonnegative and at least one is positive, so q(x)>0q(\mathbf{x}) > 0. Conversely, a unit eigenvector qi\mathbf{q}_i gives

q(qi)=qi⊤(λiqi)=λi,q(\mathbf{q}_i) = \mathbf{q}_i^{\top}(\lambda_i\mathbf{q}_i) = \lambda_i,

so a positive definite form has every λi>0\lambda_i > 0. The negative case follows by applying this to −A-A.

In plain words A definite form has the same strict sign in every direction. The test looks at every eigenvalue, and the signs of the entries do not decide it.

Example The form 5x2+4xy+2y25x^2 + 4xy + 2y^2 is positive definite, because its eigenvalues 66 and 11 are positive. The symmetric matrix

B=[−211−2]B = \begin{bmatrix} -2 & 1 \\ 1 & -2 \end{bmatrix}

has B(1,1)=(−1,−1)B(1, 1) = (-1, -1) and B(1,−1)=(−3,3)B(1, -1) = (-3, 3), so its eigenvalues are −1-1 and −3-3, and it is negative definite even though two of its entries are positive. Indeed

−2x2+2xy−2y2=−12(x+y)2−32(x−y)2,\begin{aligned} &-2x^2 + 2xy - 2y^2 \\[0.4em] &\quad = -\tfrac{1}{2}(x + y)^2 - \tfrac{3}{2}(x - y)^2, \end{aligned}

which is negative unless x+y=0x + y = 0 and x−y=0x - y = 0, that is, unless x=y=0x = y = 0.

Positive and negative semidefinite

Definition A real symmetric n×nn \times n matrix AA, and its form qq, are positive semidefinite if q(x)≥0q(\mathbf{x}) \ge 0 for every x\mathbf{x} in Rn\mathbb{R}^n, and negative semidefinite if q(x)≤0q(\mathbf{x}) \le 0 for every x\mathbf{x}. The same argument in eigen-coordinates shows that AA is positive semidefinite if and only if all its eigenvalues are nonnegative, and negative semidefinite if and only if all are nonpositive. The classes are inclusive. A positive definite matrix is also positive semidefinite, and the zero matrix is both positive and negative semidefinite but neither positive nor negative definite. For a positive semidefinite AA, the value q(x)q(\mathbf{x}) is 00 exactly when Ax=0A\mathbf{x} = \mathbf{0}. Indeed λ1z12+⋯+λnzn2=0\lambda_1 z_1^2 + \cdots + \lambda_n z_n^2 = 0 with every λi≥0\lambda_i \ge 0 forces zi=0z_i = 0 whenever λi>0\lambda_i > 0, so x\mathbf{x} is a combination of eigenvectors for the eigenvalue 00, and these lie in Null⁡A\operatorname{Null} A. As a consequence, a positive semidefinite matrix is positive definite exactly when it is invertible.

In plain words A semidefinite form never changes sign, but it may be flat in some directions. For a positive semidefinite form the flat directions are exactly the null space of its matrix.

Example The form (x+2y)2=x2+4xy+4y2(x + 2y)^2 = x^2 + 4xy + 4y^2 has the matrix

C=[1224],C = \begin{bmatrix} 1 & 2 \\ 2 & 4 \end{bmatrix},

with C(1,2)=(5,10)C(1, 2) = (5, 10) and C(2,−1)=0C(2, -1) = \mathbf{0}, so its eigenvalues are 55 and 00. It is positive semidefinite but not positive definite. Its zeros are the solutions of x+2y=0x + 2y = 0, the multiples of (2,−1)(2, -1), and these make up Null⁡C\operatorname{Null} C. The form −(x+2y)2-(x + 2y)^2 is negative semidefinite, with the same flat line.

Indefinite form

Definition A real symmetric matrix AA, and its form qq, are indefinite if qq takes both signs, that is, q(u)>0q(\mathbf{u}) > 0 and q(w)<0q(\mathbf{w}) < 0 for some vectors u\mathbf{u} and w\mathbf{w}. This happens if and only if AA has at least one positive and at least one negative eigenvalue. The signs of the eigenvalues therefore classify every real symmetric matrix.

EigenvaluesClass
all >0> 0positive definite
all <0< 0negative definite
all ≥0\ge 0 and some =0= 0positive semidefinite, not definite
all ≤0\le 0 and some =0= 0negative semidefinite, not definite
some >0> 0 and some <0< 0indefinite

The zero matrix belongs to both semidefinite rows. Two vectors with values of opposite signs prove that a form is indefinite without computing any eigenvalue. For an indefinite form, q(x)=0q(\mathbf{x}) = 0 does not mean Ax=0A\mathbf{x} = \mathbf{0}, since positive and negative terms can cancel.

In plain words An indefinite form rises in some directions and falls in others, like a saddle. In two variables its nonzero level curves are hyperbolas rather than ellipses.

Example The form x2−y2x^2 - y^2 has the matrix diag⁡(1,−1)\operatorname{diag}(1, -1) and is indefinite, since q(1,0)=1q(1, 0) = 1 and q(0,1)=−1q(0, 1) = -1. Its value at (1,1)(1, 1) is 00, yet the matrix sends (1,1)(1, 1) to (1,−1)(1, -1), not to 0\mathbf{0}. Positive entries do not prevent indefiniteness either. The matrix with rows (1,2)(1, 2) and (2,1)(2, 1) has only positive entries, but its eigenvalues are 33 and −1-1, and its form x2+4xy+y2x^2 + 4xy + y^2 gives q(1,1)=6q(1, 1) = 6 and q(1,−1)=−2q(1, -1) = -2.

Check yourself

  1. Write the symmetric matrix of q(x,y)=5x2+6xy+5y2q(x, y) = 5x^2 + 6xy + 5y^2 and classify the form. What goes wrong if the coefficient 66 is placed in both off-diagonal positions?
Show the answer

Half of the cross-term coefficient goes in each off-diagonal position, so

A=[5335].A = \begin{bmatrix} 5 & 3 \\ 3 & 5 \end{bmatrix}.

Since A(1,1)=(8,8)A(1, 1) = (8, 8) and A(1,−1)=(2,−2)A(1, -1) = (2, -2), the eigenvalues are 88 and 22. Both are positive, so qq is positive definite. In the principal-axis coordinates z1=(x+y)/2z_1 = (x + y)/\sqrt{2} and z2=(x−y)/2z_2 = (x - y)/\sqrt{2} the form is 8z12+2z228z_1^2 + 2z_2^2, and indeed 4(x+y)2+(x−y)2=5x2+6xy+5y24(x + y)^2 + (x - y)^2 = 5x^2 + 6xy + 5y^2.

The matrix with rows (5,6)(5, 6) and (6,5)(6, 5) belongs to the different form 5x2+12xy+5y25x^2 + 12xy + 5y^2. Its eigenvalues are 1111 and −1-1, and its form takes the value −2-2 at (1,−1)(1, -1), where the true form has q(1,−1)=4q(1, -1) = 4. The copying mistake would turn a positive definite form into an indefinite one.

  1. For which real numbers kk is q(x,y)=x2+2kxy+y2q(x, y) = x^2 + 2kxy + y^2 positive definite, positive semidefinite, negative semidefinite or indefinite?
Show the answer

The matrix has rows (1,k)(1, k) and (k,1)(k, 1). It sends (1,1)(1, 1) to (1+k)(1,1)(1 + k)(1, 1) and (1,−1)(1, -1) to (1−k)(1,−1)(1 - k)(1, -1), so for every kk the eigenvalues are 1+k1 + k and 1−k1 - k, and

q=(1+k)z12+(1−k)z22q = (1 + k)z_1^2 + (1 - k)z_2^2

with z1=(x+y)/2z_1 = (x + y)/\sqrt{2} and z2=(x−y)/2z_2 = (x - y)/\sqrt{2}.

When −1<k<1-1 < k < 1, both eigenvalues are positive and qq is positive definite.

When k=1k = 1 or k=−1k = -1, the eigenvalues are 22 and 00, so qq is positive semidefinite but not positive definite. For k=1k = 1 the form is (x+y)2(x + y)^2, which is 00 on the line y=−xy = -x, the null space of its matrix.

Since the classes are inclusive, qq is positive semidefinite exactly when −1≤k≤1-1 \le k \le 1.

When k>1k > 1 or k<−1k < -1, one eigenvalue is positive and the other negative, so qq is indefinite. For example k=2k = 2 gives q(1,1)=6q(1, 1) = 6 and q(1,−1)=−2q(1, -1) = -2.

The form is never negative semidefinite, and so never negative definite, because q(1,0)=1>0q(1, 0) = 1 > 0 for every kk. Alternatively, the eigenvalues add up to 22, so they cannot both be nonpositive.

  1. Classify q(x,y,z)=x2+y2+z2−xy−yz−xzq(x, y, z) = x^2 + y^2 + z^2 - xy - yz - xz and find every vector with q=0q = 0.
Show the answer

Each cross-term coefficient is −1-1, so each off-diagonal entry is −12-\frac{1}{2}, and

A=12[2−1−1−12−1−1−12].A = \frac{1}{2}\begin{bmatrix} 2 & -1 & -1 \\ -1 & 2 & -1 \\ -1 & -1 & 2 \end{bmatrix}.

The iith entry of AxA\mathbf{x} is xi−12(s−xi)=32xi−12sx_i - \frac{1}{2}(s - x_i) = \frac{3}{2}x_i - \frac{1}{2}s, where s=x+y+zs = x + y + z. So A(1,1,1)=0A(1, 1, 1) = \mathbf{0}, and every nonzero vector of the plane s=0s = 0, such as (1,−1,0)(1, -1, 0), is an eigenvector for 32\frac{3}{2}. The eigenvalues are 00, 32\frac{3}{2} and 32\frac{3}{2}, all nonnegative with one equal to 00, so qq is positive semidefinite but not positive definite.

By the semidefinite case, q(x)=0q(\mathbf{x}) = 0 exactly when x\mathbf{x} is in Null⁡A\operatorname{Null} A, which is the line of multiples of (1,1,1)(1, 1, 1). The identity

2q=(x−y)2+(y−z)2+(z−x)2\begin{aligned} 2q &= (x - y)^2 + (y - z)^2 \\[0.4em] &\quad + (z - x)^2 \end{aligned}

confirms both conclusions, since a sum of squares is never negative and is 00 exactly when x=y=zx = y = z.

How this lesson connects