Companion page: Chapter 6 Matlab resources — commands for trying out the material below on a machine.

Least squares (Chapter 3) found the best fit to some data by minimising a sum of squared errors. Behind that calculation is a question which this chapter asks directly: when does it make sense to minimise a function at all? For a quadratic function the answer turns out to be a property of a symmetric matrix, called positive definiteness. The chapter starts from the simplest quadratics, arrives at the definition, and then proves four equivalent tests for it.

1. When does minimising make sense?

1.1. One variable

Take

\begin{equation} \phi(x) = a + b(x-c)^2 , \end{equation}

with real constants \(a\), \(b\), \(c\). Since \((x-c)^2 \geq 0\), with equality only at \(x = c\), there are three cases (Figure 1).

  • \(b > 0\). Then \(\phi(x) \geq a\), with equality only at \(x = c\). The minimum value is \(a\), and it is reached at exactly one point.

  • \(b < 0\). The parabola opens downwards, and \(\phi(x)\) decreases without limit as \(x\) moves away from \(c\). There is no minimum, and asking for one is meaningless; \(x = c\) is a maximum instead.

  • \(b = 0\). Then \(\phi = a\) everywhere. Every \(x\) is a minimiser, so there is no particular point to find.

So minimising \(\phi\) gives a definite answer, one minimiser, exactly when \(b > 0\).

pd parab
Figure 1. The three cases of (1). Only \(b > 0\) gives a minimum at a single point.

Near a point where its derivative is zero, a smooth function agrees with (1) up to terms of higher order. By Taylor’s theorem, if \(\phi'(c) = 0\) then \(\phi(x) \approx \phi(c) + \tfrac12\phi''(c)(x-c)^2\) for \(x\) near \(c\), which is (1) with \(a = \phi(c)\) and \(b = \tfrac12\phi''(c)\). This is where the second-derivative test of calculus comes from: \(\phi''(c) > 0\) gives a local minimum and \(\phi''(c) < 0\) a local maximum. When \(\phi''(c) = 0\) the test says nothing: \(x^4\) has a minimum at \(0\), and \(x^3\) has neither. (This is calculus, and is not proved here; the rest of the chapter works with exact quadratics.)

1.2. Two variables

Now take

\begin{equation} \psi(x_1,x_2) = a + b_1(x_1-c_1)^2 + b_2(x_2-c_2)^2 . \end{equation}

The two variables are separate, so each coefficient can be looked at on its own.

  • \(b_1 > 0\) and \(b_2 > 0\). Then \(\psi \geq a\), with equality only at \((c_1,c_2)\): a single minimiser. The graph is a bowl.

  • \(b_1 > 0 > b_2\) (or the other way round). Along the line \(x_2 = c_2\), \(\psi\) has its minimum at \(x_1 = c_1\); along the line \(x_1 = c_1\) it has its maximum at \(x_2 = c_2\). The point \((c_1,c_2)\) is a saddle, and \(\psi\) has no minimum. The standard example is \(x_1^2 - x_2^2\).

  • \(b_1 < 0\) and \(b_2 < 0\). An upside-down bowl, with no minimum.

  • One coefficient zero and the other positive, say \(b_2 = 0 < b_1\). Then \(\psi \geq a\), with equality at every point of the line \(x_1 = c_1\) (a trough). A minimum exists but the minimiser is not unique. (If the other coefficient is negative there is no minimum, and if both are zero every point is a minimiser.)

So \(\psi\) has a single minimiser exactly when \(b_1 > 0\) and \(b_2 > 0\).

1.3. A cross term

The general quadratic in two variables also has a product term. Write \(u_1 = x_1 - c_1\) and \(u_2 = x_2 - c_2\) for the distances from the centre, and consider

\begin{equation} \psi(x_1,x_2) = a + a_{11}u_1^2 + 2a_{12}u_1u_2 + a_{22}u_2^2 . \end{equation}

The variables are now mixed, and the signs of \(a_{11}\) and \(a_{22}\) alone do not settle the question: \(u_1^2 + 4u_1u_2 + u_2^2\) is negative at \(u = (1,-1)\). Completing the square separates them again. If \(a_{11} \neq 0\),

\begin{equation} \begin{split} a_{11}u_1^2 &+ 2a_{12}u_1u_2 + a_{22}u_2^2 \\ &= a_{11}\Big(u_1 + \frac{a_{12}}{a_{11}}u_2\Big)^2 + \Big(a_{22} - \frac{a_{12}^2}{a_{11}}\Big)u_2^2 . \end{split} \end{equation}

In the variables \(v_1 = u_1 + (a_{12}/a_{11})u_2\) and \(v_2 = u_2\), this is (2) with \(b_1 = a_{11}\) and \(b_2 = a_{22} - a_{12}^2/a_{11}\). The change from \((u_1,u_2)\) to \((v_1,v_2)\) can be undone (\(u_2 = v_2\), \(u_1 = v_1 - (a_{12}/a_{11})v_2\)), so a single minimiser in one set of variables is a single minimiser in the other. By the previous subsection, \(\psi\) has a single minimiser exactly when

\begin{equation} a_{11} > 0 \qquad\text{and}\qquad a_{11}a_{22} > a_{12}^2 . \end{equation}

If \(a_{11} = 0\), (5) fails, and rightly so: the quadratic part is then \(2a_{12}u_1u_2 + a_{22}u_2^2\). If \(a_{12} \neq 0\) it takes negative values (fix \(u_2 \neq 0\) and let \(u_1\) grow with the opposite sign to \(a_{12}u_2\)), so \(\psi\) has no minimum; if \(a_{12} = 0\) it is \(a_{22}u_2^2\), which does not involve \(u_1\), so a minimiser, if there is one, is not unique.

If (3) comes from a smooth function \(\phi(x_1,x_2)\) through its Taylor expansion about a point where both first derivatives vanish, then \(a_{11} = \tfrac12\,\partial^2\phi/\partial x_1^2\), \(a_{12} = \tfrac12\,\partial^2\phi/\partial x_1\partial x_2\) and \(a_{22} = \tfrac12\,\partial^2\phi/\partial x_2^2\), and (5) is the second-derivative condition of calculus for a local minimum in two variables. As in one variable, this is the motivation, not a proof.

1.4. The matrix form

The quadratic part of (3) is a matrix product:

\begin{equation} \begin{split} a_{11}u_1^2 &+ 2a_{12}u_1u_2 + a_{22}u_2^2 \\ &= \begin{bmatrix} u_1 & u_2 \end{bmatrix}\begin{bmatrix} a_{11} & a_{12} \\ a_{12} & a_{22} \end{bmatrix}\begin{bmatrix} u_1 \\ u_2 \end{bmatrix} = u^TAu . \end{split} \end{equation}

The cross coefficient \(2a_{12}\) has been split equally between the two off-diagonal entries, so \(A\) is symmetric. Nothing is lost by insisting on this. For any square matrix \(B\), the number \(u^TBu\) equals its own transpose \(u^TB^Tu\), so \(u^TBu = u^T\tfrac12(B+B^T)u\), and \(\tfrac12(B + B^T)\) is symmetric. Only the symmetric part of a matrix is seen by \(u^TBu\).

The same form works in \(n\) variables. For a real symmetric \(n\times n\) matrix \(A\), the function \(x \mapsto x^TAx\) is called the quadratic form of \(A\), and the general quadratic of the kind above is

\begin{equation} \psi(x) = a + (x-c)^TA(x-c), \qquad x, c \in \mathbb{R}^n . \end{equation}

2. Positive definite matrices

The conditions found above say that the quadratic part of \(\psi\) is positive away from the centre. This is the property that gets a name.

Definition. A real symmetric \(n\times n\) matrix \(A\) is positive definite if \(x^TAx > 0\) for every nonzero \(x \in \mathbb{R}^n\). It is positive semidefinite if \(x^TAx \geq 0\) for every \(x\), negative definite if \(x^TAx < 0\) for every nonzero \(x\), negative semidefinite if \(x^TAx \leq 0\) for every \(x\), and indefinite if \(x^TAx\) takes both positive and negative values.

In the examples of Section 1.2, the bowl has a positive definite matrix, the trough with a line of minimisers a positive semidefinite one, the saddle an indefinite one, and the upside-down bowl a negative definite one. The following theorem is the question we started with, answered for every quadratic of the form (7).

Theorem 6.1. Let \(A\) be a real symmetric \(n\times n\) matrix, \(c \in \mathbb{R}^n\) and \(a \in \mathbb{R}\), and let \(\psi(x) = a + (x-c)^TA(x-c)\). Then \(\psi\) has exactly one minimiser if and only if \(A\) is positive definite. In that case the minimiser is \(x = c\) and the minimum value is \(a\).

Proof

Write \(u = x - c\). If \(A\) is positive definite, then \(\psi(x) - a = u^TAu > 0\) for every \(x \neq c\), so \(c\) is the only minimiser.

If \(A\) is not positive definite, there is a nonzero \(u_0\) with \(u_0^TAu_0 \leq 0\). Along the line \(x = c + tu_0\),

\begin{equation*} \psi(c + tu_0) = a + t^2\,u_0^TAu_0 . \end{equation*}

If \(u_0^TAu_0 < 0\) this decreases without limit as \(t\) grows, so \(\psi\) has no minimum at all. Otherwise \(u_0^TAu_0 = 0\). If some other vector gives a negative value, the same argument applies to it. If none does, then \(A\) is positive semidefinite, \(\psi \geq a\) everywhere, and \(\psi = a\) at every point of the line \(c + tu_0\), so the minimiser is not unique. In every case \(\psi\) fails to have exactly one minimiser.

For \(n = 2\), Section 1.3 together with Theorem 6.1 has already found a test: the matrix in (6) is positive definite exactly when (5) holds. The next section gives four tests for \(n\times n\) matrices.

3. Four tests for positive definiteness

Throughout this section \(A\) is a real symmetric \(n\times n\) matrix. The example

\begin{equation} A = \begin{bmatrix} 5 & 4 \\ 4 & 5 \end{bmatrix}, \quad x^TAx = 5x_1^2 + 8x_1x_2 + 5x_2^2 , \end{equation}

is used for each test. By (5) it is positive definite, since \(5 > 0\) and \(5\cdot 5 = 25 > 16 = 4^2\).

3.1. Test 1: eigenvalues

Theorem 6.2. \(A\) is positive definite if and only if all its eigenvalues are positive.

Proof

The eigenvalues of \(A\) are real by Theorem 5.16, and by the spectral theorem (Corollary 5.23) \(A\) has \(n\) real orthonormal eigenvectors \(q_1,\ldots,q_n\), with \(Aq_i = \lambda_iq_i\).

Suppose \(A\) is positive definite. Taking \(x = q_i\), \(0 < q_i^TAq_i = \lambda_i\,q_i^Tq_i = \lambda_i\).

Conversely, suppose every \(\lambda_i > 0\), and let \(x \neq 0\). The \(q_i\) form a basis, so \(x = \sum_i c_iq_i\) for some numbers \(c_i\), not all zero. Then \(Ax = \sum_j c_j\lambda_jq_j\), and by orthonormality

\begin{equation*} \begin{split} x^TAx &= \Big(\sum_{i=1}^n c_iq_i\Big)^T\Big(\sum_{j=1}^n c_j\lambda_jq_j\Big) \\ &= \sum_{i=1}^n c_i^2\lambda_i\,q_i^Tq_i = \sum_{i=1}^n \lambda_ic_i^2 > 0 . \end{split} \end{equation*}

For a \(2\times 2\) matrix the test agrees with (5): \(\lambda_1\lambda_2 = \det A = a_{11}a_{22} - a_{12}^2\) (Theorem 5.4) and \(\lambda_1 + \lambda_2 = a_{11} + a_{22}\) (Theorem 5.5). If (5) holds, the product is positive, so the two eigenvalues have the same sign; and \(a_{22} > 0\) too (since \(a_{11}a_{22} > a_{12}^2 \geq 0\) with \(a_{11} > 0\)), so the sum is positive and both are positive. For (8), \(\lambda = 1\) and \(\lambda = 9\).

3.2. Test 2: pivots

Since \(A\) is symmetric, when elimination runs to completion without row exchanges, with \(n\) nonzero pivots, it gives \(A = LDL^T\) (Chapter 1, Theorem 1.10), with \(L\) unit lower triangular and the pivots \(d_1,\ldots,d_n\) on the diagonal of \(D\).

Theorem 6.3. \(A\) is positive definite if and only if elimination on \(A\) without row exchanges produces \(n\) pivots, all positive.

Proof

Suppose the pivots are all positive, so that \(A = LDL^T\). For any \(x\), put \(y = L^Tx\). Then

\begin{equation*} x^TAx = x^TLDL^Tx = y^TDy = d_1y_1^2 + d_2y_2^2 + \cdots + d_ny_n^2 . \end{equation*}

\(L^T\) is triangular with ones on the diagonal, so it is invertible, and \(x \neq 0\) gives \(y \neq 0\). With all \(d_i > 0\), the sum is then positive.

Conversely, suppose \(A\) is positive definite. First, elimination does run without row exchanges. Let \(A_k\) be the upper left \(k\times k\) block of \(A\). For \(z \in \mathbb{R}^k\), put \(x = (z, 0, \ldots, 0)\); then \(x^TAx = z^TA_kz\), so \(A_k\) is positive definite too. By Theorem 6.2 its eigenvalues are positive, and their product \(\det A_k\) (Theorem 5.4) is positive, so \(A_k\) is nonsingular. This holds for every \(k\), so Theorem 1.6 says that elimination produces \(n\) nonzero pivots without row exchanges, and \(A = LDL^T\). Second, the pivots are positive: take \(x = (L^T)^{-1}e_i\), so that \(y = L^Tx = e_i\), and the identity above gives \(d_i = x^TAx > 0\).

The test needs elimination to run without row exchanges. For \(\begin{bmatrix} 0 & 1 \\ 1 & 0\end{bmatrix}\) the first pivot is zero, and the matrix is not positive definite: \(x = (1,-1)\) gives \(x^TAx = -2\). For a \(2\times 2\) matrix the pivots are \(a_{11}\) and \(a_{22} - a_{12}^2/a_{11}\) (the second row minus \(a_{12}/a_{11}\) times the first), exactly the two coefficients that completing the square produced in (4); the substitution \(y = L^Tx\) in the proof is the change of variables from \((u_1,u_2)\) to \((v_1,v_2)\) in Section 1.3. Elimination on a symmetric matrix is completing the square. For (8), the pivots are \(d_1 = 5\) and \(d_2 = 5 - 4\cdot\tfrac45 = \tfrac95\), both positive. Theorem 6.3 shows that a positive definite matrix never needs a row exchange, but it does not promise pivots of a comfortable size. The \(3\times 3\) Hilbert matrix of Chapter 3 has pivots \(1\), \(1/12\) and \(1/180\), so by Theorem 6.3 it is positive definite, and yet its pivots shrink quickly.

3.3. Test 3: upper left determinants

Theorem 6.4. \(A\) is positive definite if and only if \(\det A_k > 0\) for every upper left \(k\times k\) block \(A_k\), \(k = 1,\ldots,n\).

Proof

If \(A\) is positive definite, each \(A_k\) is positive definite (as in the proof of Theorem 6.3), so by Theorems 6.2 and 5.4 \(\det A_k > 0\).

Conversely, suppose every \(\det A_k > 0\). Then every \(A_k\) is nonsingular, so by Theorem 1.6 elimination runs without row exchanges, and by the pivot formula of Chapter 4 (Theorem 4.8), \(\det A_k = d_1d_2\cdots d_k\). So \(d_1 = \det A_1 > 0\) and \(d_k = \det A_k/\det A_{k-1} > 0\) for \(k \geq 2\). All pivots are positive, and Theorem 6.3 gives the result.

For \(n = 2\) this is exactly (5): \(\det A_1 = a_{11}\) and \(\det A_2 = a_{11}a_{22} - a_{12}^2\). For (8) the two determinants are \(5\) and \(9\), the products \(d_1 = 5\) and \(d_1d_2 = 9\) of the pivots.

3.4. Test 4: \(A = R^TR\)

Theorem 6.5. \(A\) is positive definite if and only if \(A = R^TR\) for some matrix \(R\) with independent columns.

Proof

Suppose \(A = R^TR\) with independent columns. Then \(x^TAx = x^TR^TRx = (Rx)^T(Rx) = \|Rx\|^2 \geq 0\), and since the columns of \(R\) are independent, \(Rx \neq 0\) whenever \(x \neq 0\). So \(x^TAx > 0\) for every nonzero \(x\).

Conversely, suppose \(A\) is positive definite. By Theorem 6.3, \(A = LDL^T\) with every \(d_i > 0\). Let \(\sqrt D\) be the diagonal matrix with entries \(\sqrt{d_i}\), so that \(\sqrt D\sqrt D = D\), and put \(R = \sqrt D\,L^T\). Then

\begin{equation*} R^TR = L\sqrt D\,\sqrt D\,L^T = LDL^T = A . \end{equation*}

\(R\) is upper triangular with diagonal entries \(\sqrt{d_i} > 0\), so it is invertible and its columns are independent.

The \(R\) built in the proof is square and upper triangular; the factorization \(A = R^TR\) of this form is called the Cholesky factorization. Chapter 1 wrote the same factorization as \(A = RR^T\) with the lower triangular \(R = LD^{1/2}\); the \(R\) here is its transpose. Among upper triangular factors with positive diagonal, this one is the only one: writing such a factor as \(R = D^{1/2}U\) with \(U\) unit upper triangular gives \(A = U^TDU\), and Theorem 1.5 fixes \(U = L^T\) and \(D\). Factors of other shapes exist: multiplying \(R\) on the left by any orthogonal matrix \(Q\) gives another factor with independent columns, since \((QR)^T(QR) = R^TQ^TQR = R^TR\). For (8),

\begin{equation*} \begin{gathered} R = \begin{bmatrix} \sqrt5 & 0 \\ 0 & 3/\sqrt5 \end{bmatrix}\begin{bmatrix} 1 & 4/5 \\ 0 & 1 \end{bmatrix} = \begin{bmatrix} \sqrt5 & 4/\sqrt5 \\ 0 & 3/\sqrt5 \end{bmatrix}, \\ R^TR = \begin{bmatrix} 5 & 4 \\ 4 & \tfrac{16}{5} + \tfrac95 \end{bmatrix} = A . \end{gathered} \end{equation*}

Test 4 also shows why the hypothesis of Chapter 3 is the natural one. Let \(M\) be an \(m\times n\) matrix, the \(A\) of the least squares problem there. The least squares error expands as

\begin{equation*} \begin{split} \|Mx-b\|^2 &= (Mx-b)^T(Mx-b) \\ &= x^TM^TMx - 2b^TMx + b^Tb , \end{split} \end{equation*}

whose quadratic part has the symmetric matrix \(M^TM\). With \(R = M\), Theorem 6.5 says that \(M^TM\) is positive definite whenever \(M\) has independent columns, which is the hypothesis under which Theorem 3.12 found a unique least squares solution.

The four tests can be summarised in one statement.

Corollary 6.6. For a real symmetric matrix \(A\), the following are equivalent: \(A\) is positive definite; all its eigenvalues are positive; elimination without row exchanges gives all pivots positive; all its upper left determinants are positive; \(A = R^TR\) with \(R\) having independent columns.

4. Positive semidefinite matrices

Two of the tests carry over to the semidefinite case with \(\geq\) in place of \(>\).

Theorem 6.7. For a real symmetric matrix \(A\), the following are equivalent: \(A\) is positive semidefinite; all its eigenvalues are \(\geq 0\); \(A = R^TR\) for some matrix \(R\), whose columns may be dependent.

Proof

The proof of Theorem 6.2 goes through with \(\geq\) in place of \(>\): \(\lambda_i = q_i^TAq_i \geq 0\), and conversely \(x^TAx = \sum_i\lambda_ic_i^2 \geq 0\). If \(A = R^TR\), then \(x^TAx = \|Rx\|^2 \geq 0\). Finally, if all \(\lambda_i \geq 0\), write \(A = Q\Lambda Q^T\) (Corollary 5.23), let \(\sqrt\Lambda\) have entries \(\sqrt{\lambda_i}\), and put \(R = \sqrt\Lambda\,Q^T\); then \(R^TR = Q\sqrt\Lambda\sqrt\Lambda Q^T = A\).

The other two tests do not carry over in the obvious way. The matrix

\begin{equation*} \begin{bmatrix} 0 & 0 \\ 0 & -1 \end{bmatrix} \end{equation*}

has upper left determinants \(0\) and \(0\), both \(\geq 0\), but it is not positive semidefinite, since \(x = (0,1)\) gives \(x^TAx = -1\). A version of the pivot test also needs care once a pivot is zero, and is not developed here.

5. Visualising quadratic forms

For a diagonal matrix the curve \(x^TAx = 1\) is easy to draw. If \(a_{11}, a_{22} > 0\), then \(a_{11}x_1^2 + a_{22}x_2^2 = 1\) is an ellipse with semi-axes \(1/\sqrt{a_{11}}\) along the \(x_1\) axis and \(1/\sqrt{a_{22}}\) along the \(x_2\) axis.

For a general positive definite \(A\), change to the basis of eigenvectors. By Corollary 5.23, \(A = Q\Lambda Q^T\) with \(Q\) orthogonal. Put \(y = Q^Tx\); since \(Q^{-1} = Q^T\), this is the coordinate column of \(x\) in the basis of the columns of \(Q\) (Chapter 5, change of basis). Then

\begin{equation} \begin{split} x^TAx &= x^TQ\Lambda Q^Tx = y^T\Lambda y \\ &= \lambda_1y_1^2 + \lambda_2y_2^2 + \cdots + \lambda_ny_n^2 . \end{split} \end{equation}

In the eigenvector coordinates the cross terms have gone, and the quadratic form has the separated shape of (2) with \(b_i = \lambda_i\). In these coordinates Test 1 says that each coefficient of the separated form is positive, just as in Section 1.2. In two dimensions, \(x^TAx = 1\) is the ellipse \(\lambda_1y_1^2 + \lambda_2y_2^2 = 1\), with its axes along the eigenvectors and semi-axes \(1/\sqrt{\lambda_1}\) and \(1/\sqrt{\lambda_2}\). These are the principal axes of the ellipse.

For (8), \(\lambda_1 = 1\) with unit eigenvector \(q_1 = (1,-1)/\sqrt2\), and \(\lambda_2 = 9\) with \(q_2 = (1,1)/\sqrt2\). The curve \(5x_1^2 + 8x_1x_2 + 5x_2^2 = 1\) is \(y_1^2 + 9y_2^2 = 1\): an ellipse with semi-axis \(1\) along \(q_1\) and \(1/3\) along \(q_2\) (Figure 2). As a check, \(x = q_2/3 = (1,1)/(3\sqrt2)\) gives \(5x_1^2 + 8x_1x_2 + 5x_2^2 = 18/18 = 1\).

pd ellipse
Figure 2. The curve \(5x_1^2 + 8x_1x_2 + 5x_2^2 = 1\). Its principal axes lie along the eigenvectors \(q_1\) and \(q_2\) of the matrix (8), with semi-axes \(1/\sqrt{\lambda_1} = 1\) and \(1/\sqrt{\lambda_2} = 1/3\).

Home