Tutorials › Linear Algebra › Completing Squares And LDLᵀ Factorization

Quadratic Forms and Definiteness · Tutorial 769 of 1000

Completing Squares And LDLᵀ Factorization

Use symmetric elimination to complete squares, construct an \(LDL^{\top}\) factorization, and interpret its pivots.

Advanced 10 min read

What You'll Learn

  • Complete a positive definite quadratic form one variable at a time.
  • Construct a unit lower triangular \(L\) and diagonal \(D\) with \(A=LDL^{\top}\).
  • Explain why each elimination pivot is positive for a positive definite matrix.
  • Relate the pivots to ratios of successive leading principal minors.
  • Recognize when a zero or negative pivot prevents positive definiteness.

Completing Squares Reveals the Matrix

A quadratic form may be written as \(\mathbf{x}^{\top}\mathbf{A}\mathbf{x}\), where \(\mathbf{A}\) is symmetric and \(\mathbf{x}\) is a column vector. If the form is positive definite, its value is positive for every nonzero \(\mathbf{x}\). Completing squares rewrites that expression as a sum of positive multiples of squares of linear combinations of the coordinates. The coefficients of those squares are not arbitrary: they are exactly the successive pivots obtained by eliminating variables in order.

We work over \(\mathbb{R}\). A symmetric matrix \(\mathbf{A}\in\mathbb{R}^{n\times n}\) is positive definite if \(\mathbf{x}^{\top}\mathbf{A}\mathbf{x}>0\) for every \(\mathbf{x}\ne\mathbf{0}\). A matrix \(\mathbf{L}\) is unit lower triangular if it is lower triangular and every diagonal entry is \(1\). A diagonal matrix \(\mathbf{D}\) has zero entries off its main diagonal.

Key idea: Completing squares in coordinate order produces an expression of the form \(\mathbf{x}^{\top}\mathbf{A}\mathbf{x}=\sum_{k=1}^{n} d_k z_k^2\), where each \(z_k\) is a linear combination of \(x_k,\dots,x_n\). In matrix form, this is \(\mathbf{A}=\mathbf{L}\mathbf{D}\mathbf{L}^{\top}\), with the \(d_k\) on the diagonal of \(\mathbf{D}\).

For a \(2\times2\) symmetric matrix, the mechanism is already visible. If \(\mathbf{A}=\begin{bmatrix}a&b\\b&c\end{bmatrix}\) and \(a\ne0\), then

$$ ax_1^2+2bx_1x_2+cx_2^2 =a\left(x_1+\frac{b}{a}x_2\right)^2 +\left(c-\frac{b^2}{a}\right)x_2^2. $$

The first square uses the pivot \(a\). The remaining coefficient \(c-b^2/a\) is the next pivot. For a positive definite matrix, both are positive: testing \(\mathbf{x}=(1,0)^{\top}\) gives \(a>0\), and testing \(\mathbf{x}=(-b/a,1)^{\top}\ne\mathbf{0}\) makes the quadratic form equal to \(c-b^2/a>0\).

Worked Example: Completing Squares for a Two-Variable Form

For \(\mathbf{A}=\begin{bmatrix}3&1\\1&2\end{bmatrix}\), complete the square and find an \(LDL^{\top}\) factorization.

The quadratic form is \(3x_1^2+2x_1x_2+2x_2^2\). Completing the square in \(x_1\) gives

$$ 3x_1^2+2x_1x_2+2x_2^2 =3\left(x_1+\frac{1}{3}x_2\right)^2+\frac{5}{3}x_2^2. $$

Thus \(d_1=3\), \(d_2=\tfrac53\), and the linear combinations inside the squares are encoded by \(\mathbf{L}^{\top}\mathbf{x}\), where

$$ \mathbf{L}=\begin{bmatrix}1&0\\\frac13&1\end{bmatrix}, \qquad \mathbf{D}=\begin{bmatrix}3&0\\0&\frac53\end{bmatrix}. $$

Multiplying confirms the factorization:

$$ \mathbf{L}\mathbf{D} =\begin{bmatrix}3&0\\1&\frac53\end{bmatrix}, \qquad \mathbf{L}\mathbf{D}\mathbf{L}^{\top} =\begin{bmatrix}3&1\\1&\frac13+\frac53\end{bmatrix} =\begin{bmatrix}3&1\\1&2\end{bmatrix} =\mathbf{A}. $$

Check: for \(\mathbf{x}=(x_1,x_2)^{\top}\), \(\mathbf{L}^{\top}\mathbf{x}=(x_1+\tfrac13x_2,x_2)^{\top}\). Therefore \((\mathbf{L}^{\top}\mathbf{x})^{\top}\mathbf{D}(\mathbf{L}^{\top}\mathbf{x})=3(x_1+\tfrac13x_2)^2+\tfrac53x_2^2\), which expands to the original form.

The Block Step: One Square and a Smaller Form

The same calculation works in any dimension. Write a symmetric matrix in block form, separating its first row and column:

$$ \mathbf{A}= \begin{bmatrix} a&\mathbf{b}^{\top}\\ \mathbf{b}&\mathbf{C} \end{bmatrix}, \qquad \mathbf{x}= \begin{bmatrix} x_1\\\mathbf{y} \end{bmatrix}. $$

Here \(a\) is a scalar, \(\mathbf{b}\in\mathbb{R}^{n-1}\), \(\mathbf{C}\in\mathbb{R}^{(n-1)\times(n-1)}\) is symmetric, and \(\mathbf{y}\in\mathbb{R}^{n-1}\). When \(a\ne0\), expanding the right-hand side verifies the identity

$$ \mathbf{x}^{\top}\mathbf{A}\mathbf{x} =a\left(x_1+\frac{\mathbf{b}^{\top}\mathbf{y}}{a}\right)^2 +\mathbf{y}^{\top} \left(\mathbf{C}-\frac{\mathbf{b}\mathbf{b}^{\top}}{a}\right)\mathbf{y}. $$

The smaller symmetric matrix \(\mathbf{C}-\mathbf{b}\mathbf{b}^{\top}/a\) is the Schur complement of the scalar block \(a\) in this partition. The name is useful, but the essential point is its origin: after completing the first square, this matrix gives the remaining quadratic form.

If \(\mathbf{A}\) is positive definite, then \(a>0\), by evaluating the form at \((1,\mathbf{0})^{\top}\). The Schur complement is also positive definite. Indeed, for any \(\mathbf{y}\ne\mathbf{0}\), choose \(x_1=-\mathbf{b}^{\top}\mathbf{y}/a\). The resulting \(\mathbf{x}\) is nonzero, and the completed-square identity gives \(\mathbf{x}^{\top}\mathbf{A}\mathbf{x} =\mathbf{y}^{\top}(\mathbf{C}-\mathbf{b}\mathbf{b}^{\top}/a)\mathbf{y}>0\).

Theorem (LDL\(\top\) factorization for positive definite matrices): Every real symmetric positive definite matrix \(\mathbf{A}\in\mathbb{R}^{n\times n}\) can be written \(\mathbf{A}=\mathbf{L}\mathbf{D}\mathbf{L}^{\top}\), where \(\mathbf{L}\) is unit lower triangular and \(\mathbf{D}=\operatorname{diag}(d_1,\dots,d_n)\) is diagonal with \(d_k>0\) for every \(k\). Conversely, any such factorization with all \(d_k>0\) gives a positive definite matrix.

Proof. We prove both directions. First suppose \(\mathbf{A}\) is positive definite. We use induction on \(n\). For \(n=1\), \(\mathbf{A}=[a]\) with \(a>0\), so take \(\mathbf{L}=[1]\) and \(\mathbf{D}=[a]\). Now suppose \(n>1\), and partition \(\mathbf{A}\) as above. We have \(a>0\), and the block calculation shows that \(\mathbf{S}=\mathbf{C}-\mathbf{b}\mathbf{b}^{\top}/a\) is symmetric positive definite. By the induction hypothesis, \(\mathbf{S}=\mathbf{L}_2\mathbf{D}_2\mathbf{L}_2^{\top}\), with \(\mathbf{L}_2\) unit lower triangular and all diagonal entries of \(\mathbf{D}_2\) positive. Set \(\mathbf{L}=\begin{bmatrix}1&\mathbf{0}^{\top}\\\mathbf{b}/a&\mathbf{L}_2\end{bmatrix}\) and \(\mathbf{D}=\begin{bmatrix}a&0\\0&\mathbf{D}_2\end{bmatrix}\). Block multiplication gives \(\mathbf{L}\mathbf{D}\mathbf{L}^{\top} =\begin{bmatrix}a&\mathbf{b}^{\top}\\\mathbf{b}&\mathbf{b}\mathbf{b}^{\top}/a+\mathbf{S}\end{bmatrix} =\mathbf{A}\). The diagonal entries of \(\mathbf{D}\) are positive. This proves existence. Conversely, suppose \(\mathbf{A}=\mathbf{L}\mathbf{D}\mathbf{L}^{\top}\) with \(\mathbf{L}\) unit lower triangular and \(d_k>0\). Such an \(\mathbf{L}\) is invertible: solving \(\mathbf{L}^{\top}\mathbf{u}=\mathbf{0}\) from the last row upwards gives \(\mathbf{u}=\mathbf{0}\). Thus if \(\mathbf{x}\ne\mathbf{0}\), then \(\mathbf{L}^{\top}\mathbf{x}\ne\mathbf{0}\), and \(\mathbf{x}^{\top}\mathbf{A}\mathbf{x} =(\mathbf{L}^{\top}\mathbf{x})^{\top}\mathbf{D}(\mathbf{L}^{\top}\mathbf{x}) =\sum_{k=1}^{n}d_k((\mathbf{L}^{\top}\mathbf{x})_k)^2>0\). So \(\mathbf{A}\) is positive definite. \(\square\)

Elimination Pivots and Leading Principal Minors

The construction in the proof is an algorithm. At each stage, take the first diagonal entry of the current symmetric matrix as a pivot, complete a square using that pivot, then continue with the Schur complement. No row exchanges are needed for a positive definite matrix, because every pivot is positive. The multipliers used to complete the squares become the entries below the diagonal of \(\mathbf{L}\).

1
Take the first pivot.
For the current symmetric matrix, set \(d_1=a_{11}\). Positive definiteness ensures \(d_1>0\).
2
Remove the first variable.
Use the multipliers \(a_{i1}/d_1\) to complete the square and form the smaller Schur complement.
3
Repeat on the smaller matrix.
The next pivot is \(d_2\), followed by \(d_3\), and so on. Place each pivot in \(\mathbf{D}\) and each multiplier in \(\mathbf{L}\).
4
Read the completed squares.
The resulting identity is \(\mathbf{x}^{\top}\mathbf{A}\mathbf{x}=(\mathbf{L}^{\top}\mathbf{x})^{\top}\mathbf{D}(\mathbf{L}^{\top}\mathbf{x})\).

The pivots can also be checked using leading principal minors. Let \(\Delta_k\) be the determinant of the upper-left \(k\times k\) block of \(\mathbf{A}\), and set \(\Delta_0=1\). In an \(LDL^{\top}\) factorization, the upper-left \(k\times k\) block factors using the upper-left \(k\times k\) block of \(\mathbf{L}\) and the first \(k\) entries of \(\mathbf{D}\). The triangular factors have diagonal entries \(1\), so their determinants are \(1\). The determinant of the diagonal factor is \(d_1\cdots d_k\). Hence \(\Delta_k=d_1\cdots d_k\), and therefore \(d_k=\Delta_k/\Delta_{k-1}\). This relation uses \(\Delta_{k-1}\ne0\), which holds here because it is a product of positive pivots (and \(\Delta_0=1\)).

Worked Example: A Three-Variable Form and Its Pivots

Factor \(\mathbf{A}=\begin{bmatrix}2&1&0\\1&3&1\\0&1&2\end{bmatrix}\) by completing squares in order. The first pivot is \(d_1=2\), and the first multiplier is \(a_{21}/d_1=1/2\); the multiplier in row 3 is \(a_{31}/d_1=0\). After removing the first variable, the remaining \(2\times2\) matrix is

$$ \begin{bmatrix}3&1\\1&2\end{bmatrix} -\frac{1}{2}\begin{bmatrix}1\\0\end{bmatrix} \begin{bmatrix}1&0\end{bmatrix} = \begin{bmatrix}\frac52&1\\1&2\end{bmatrix}. $$

The next pivot is \(d_2=5/2\). The next multiplier is \(1/(5/2)=2/5\), so the final pivot is \(d_3=2-(2/5)\cdot1=8/5\). The completed-square identity is

$$ \mathbf{x}^{\top}\mathbf{A}\mathbf{x} =2\left(x_1+\frac12x_2\right)^2 +\frac52\left(x_2+\frac25x_3\right)^2 +\frac85x_3^2. $$

Thus \(\mathbf{L}=\begin{bmatrix}1&0&0\\\frac12&1&0\\0&\frac25&1\end{bmatrix}\) and \(\mathbf{D}=\begin{bmatrix}2&0&0\\0&\frac52&0\\0&0&\frac85\end{bmatrix}\). To check by multiplication,

$$ \mathbf{L}\mathbf{D} =\begin{bmatrix}2&0&0\\1&\frac52&0\\0&1&\frac85\end{bmatrix}, \qquad \mathbf{L}\mathbf{D}\mathbf{L}^{\top} =\begin{bmatrix}2&1&0\\1&3&1\\0&1&2\end{bmatrix} =\mathbf{A}. $$

Pivot check: the leading principal determinants are \(\Delta_1=2\), \(\Delta_2=2\cdot3-1\cdot1=5\), and \(\Delta_3=2(3\cdot2-1\cdot1)-1(1\cdot2-1\cdot0)=8\). Their successive ratios are \(2\), \(5/2\), and \(8/5\), exactly the pivots found by completing squares. Since the diagonal entries of \(\mathbf{D}\) are positive, the factorization also verifies positive definiteness.

When a Pivot Is Not Positive

A positive pivot is essential to the positive-definite conclusion. For a symmetric matrix, the same square-completion calculation can still be performed when a pivot is nonzero, but a zero pivot prevents division and a negative pivot supplies a negative square coefficient. Neither outcome gives the positive diagonal matrix in the theorem.

Worked Example: A Negative Pivot Detects Failure

Consider \(\mathbf{A}=\begin{bmatrix}1&2\\2&1\end{bmatrix}\). Completing the first square gives

$$ x_1^2+4x_1x_2+x_2^2=(x_1+2x_2)^2-3x_2^2. $$

The pivots are \(d_1=1\) and \(d_2=-3\). The corresponding factorization is \(\mathbf{L}=\begin{bmatrix}1&0\\2&1\end{bmatrix}\), \(\mathbf{D}=\begin{bmatrix}1&0\\0&-3\end{bmatrix}\). Indeed, \(\mathbf{L}\mathbf{D}=\begin{bmatrix}1&0\\2&-3\end{bmatrix}\), so \(\mathbf{L}\mathbf{D}\mathbf{L}^{\top} =\begin{bmatrix}1&2\\2&4-3\end{bmatrix}=\mathbf{A}\).

Check: take \(\mathbf{x}=(-2,1)^{\top}\ne\mathbf{0}\). Then \(\mathbf{x}^{\top}\mathbf{A}\mathbf{x}=(-2)^2+4(-2)(1)+1^2=4-8+1=-3<0\). Thus the matrix is not positive definite, in agreement with the negative second pivot.

Common Pitfall: The Pivot Order Matters

Do not assume that every symmetric matrix can be processed by dividing by each diagonal pivot in turn. For example, the symmetric matrix \(\begin{bmatrix}0&1\\1&0\end{bmatrix}\) has first pivot \(0\), so the formula involving division by that pivot cannot be used. Its quadratic form is \(2x_1x_2\), which takes negative values, for instance at \((1,-1)^{\top}\). A zero pivot signals that this no-row-exchange procedure has stopped; it does not justify dividing by zero or claiming the matrix is positive definite.

For a positive definite matrix, the situation is different: the block argument proves that each successive Schur complement remains positive definite, so its first diagonal entry is positive. Consequently every pivot in the chosen order exists and is positive. This is the feature that makes completing squares both a proof of positive definiteness and a reliable way to construct the factorization.

Check Your Understanding

For each question, use square completion or the pivot interpretation, and verify any proposed factorization by multiplication.

  1. Complete the square for \(4x_1^2+4x_1x_2+3x_2^2\), and give its two pivots.
  2. For \(\mathbf{A}=\begin{bmatrix}3&1\\1&3\end{bmatrix}\), find \(\mathbf{L}\) and \(\mathbf{D}\) in an \(LDL^{\top}\) factorization.
  3. Explain why the Schur complement of the first diagonal entry of a positive definite matrix is positive definite.
  4. If the first two leading principal determinants are \(\Delta_1=5\) and \(\Delta_2=15\), what is the second elimination pivot, provided the factorization exists?
  5. Give a reason that a zero pivot does not permit the square-completion formula to be used at that step.

Test yourself: Linear Algebra final exam practice

Ready to check what you know? Work a full-length practice final, then open the complete worked solutions.

Want all 1,114 practice problems?

This tutorial covers one topic. Calc Pass covers the full Calculus AB & BC curriculum (the core of Calculus I and II): full review, every practice question, and step-by-step solutions to each one.

QR code to download the Calc Pass app

Get the Calc Pass App

Scan to download and practice on the go, with instant scoring.

Calc Pass Volume 1: 1,114 Practice Questions book cover

Vol. 1: 1,114 Questions

The complete practice question bank, organized by AB & BC topic.

View on Amazon
Calc Pass Volume 2: Solutions Manual book cover

Vol. 2: Solutions Manual

Fully worked solutions to every question in Volume 1.

View on Amazon