4.8.19 · D4Numerical Methods

Exercises — LU decomposition (numerical)

1,809 words8 min readBack to topic

Quick reminders you will reuse everywhere (all from the parent):

Figure — LU decomposition (numerical)

Level 1 — Recognition

Exercise 1.1

Which of these matrices is lower triangular, which is upper triangular, and which is neither? For the triangular ones, state whether it could be a Doolittle (ones on the diagonal).

Recall Solution
  • : entries above the diagonal are lower triangular. Diagonal is → yes, a valid Doolittle .
  • : entries below the diagonal are upper triangular. (A , not an .)
  • : below-diagonal entry , above-diagonal entry lower triangular, but diagonal is not a Doolittle (it would be a Crout-style , see Crout Decomposition).
  • : has nonzero entries both above and below → neither.

Exercise 1.2

Without multiplying anything out, state and for

Recall Solution

The determinant of a triangular matrix is the product of its diagonal (see Determinants). So In Doolittle form always, which is exactly why .


Level 2 — Application

Exercise 2.1

Find the Doolittle and for

Recall Solution

Row 1 of (top row of is ): , . Column 1 of : . Row 2 of : . Check:

Exercise 2.2

Using the from Exercise 2.1, solve with .

Recall Solution

Forward solve (top-down, one unknown per row): ; . Back solve (bottom-up): ; . Sanity:

Exercise 2.3

Factor the matrix

Recall Solution

Row 1 of : . Column 1 of : , . Row 2 of : , . Column 2 of : . Row 3 of : . Check: (multiply to confirm). ✓


Level 3 — Analysis

Exercise 3.1

The matrix is invertible (). Show that plain Doolittle fails, then repair it with Partial Pivoting to get .

Recall Solution

Failure: , so — division by zero. Plain LU dies even though is perfectly invertible; the problem is purely the zero pivot, not singularity. Repair: swap the rows so the larger-magnitude entry () sits on the pivot. The swap is the permutation matrix (see Permutation Matrices) Now Doolittle on : ; ; . To solve you'd solve then .

Exercise 3.2

For partial pivoting compares against . Perform the pivoted factorization and verify .

Recall Solution

, so swap rows: , . ; ; . Multiplier . ✓ Without pivoting we'd have had — pivoting made the multiplier small, which is exactly what keeps rounding errors bounded (see Condition Number and Numerical Stability).

Exercise 3.3

Explain, using the LU factors only, why times a sign, and compute for the matrix of Exercise 2.3.

Recall Solution

(no swaps used there), so . In Doolittle form (product of ones). Thus . If row swaps were used, each swap flips the sign once, giving the factor. For Exercise 2.3: , and no swaps, so .


Level 4 — Synthesis

Exercise 4.1

You are given the factors of some (no swaps) and asked to solve for two right-hand sides without ever re-factoring:

Recall Solution

This is the whole point of LU: factor once, solve many (see Gaussian Elimination).

RHS 1. Forward : ; ; . Back : ; ; .

RHS 2. Forward: ; ; . Back: ; ; . Notice we reused for both — no elimination redone.

Exercise 4.2

A matrix was pivoted during factorization: one row swap occurred, recorded by

L=\begin{pmatrix}1&0&0\\ \tfrac12&1&0\\0&\tfrac13&1\end{pmatrix},\quad U=\begin{pmatrix}4&2&0\\0&3&1\\0&0&2\end{pmatrix}.$$ (a) Compute $\det A$. (b) Solve $A\mathbf{x}=\mathbf{b}$ with $\mathbf{b}=(3,\,8,\,6)^\top$, remembering to permute $\mathbf{b}$. > [!recall]- Solution > **(a)** One swap → sign $(-1)^1=-1$. $\prod u_{ii}=4\cdot3\cdot2=24$. So $\det A=-24$. > **(b)** We must solve $L\mathbf{y}=P\mathbf{b}$ (the classic forgotten step!). $P$ swaps the first two entries: $P\mathbf{b}=(8,\,3,\,6)^\top$. > Forward $L\mathbf{y}=P\mathbf{b}$: $y_1=8$; $\tfrac12\cdot8+y_2=3\Rightarrow y_2=3-4=-1$; $\tfrac13(-1)+y_3=6\Rightarrow y_3=6+\tfrac13=\tfrac{19}{3}$. > Back $U\mathbf{x}=\mathbf{y}$: $2x_3=\tfrac{19}{3}\Rightarrow x_3=\tfrac{19}{6}$; $3x_2+x_3=-1\Rightarrow 3x_2=-1-\tfrac{19}{6}=-\tfrac{25}{6}\Rightarrow x_2=-\tfrac{25}{18}$; $4x_1+2x_2=8\Rightarrow 4x_1=8-2(-\tfrac{25}{18})=8+\tfrac{25}{9}=\tfrac{97}{9}\Rightarrow x_1=\tfrac{97}{36}$. > $$\mathbf{x}=\Big(\tfrac{97}{36},\,-\tfrac{25}{18},\,\tfrac{19}{6}\Big)^\top.$$ > [!mistake] L4 trap — solving $L\mathbf{y}=\mathbf{b}$ instead of $L\mathbf{y}=P\mathbf{b}$ > With $PA=LU$ stored, students grab $L,U$ and feed the **original** $\mathbf{b}$. *Why it feels right:* you're solving "$A\mathbf{x}=\mathbf{b}$," so $\mathbf{b}$ looks untouched. *The truth:* the equation you actually factored is $PA\mathbf{x}=P\mathbf{b}$, i.e. $LU\mathbf{x}=P\mathbf{b}$. Fix: **permute $\mathbf{b}$ with the same $P$ before forward substitution.** (See [[Permutation Matrices]].) --- ## Level 5 — Mastery ### Exercise 5.1 A symmetric positive-definite matrix $$A=\begin{pmatrix}4&2\\2&5\end{pmatrix}$$ has both a Doolittle $A=LU$ and a Cholesky $A=GG^\top$. Compute **both** and show the diagonal of $U$ equals the squared diagonal of $G$. > [!recall]- Solution > **Doolittle:** $u_{11}=4,\ u_{12}=2$; $\ell_{21}=2/4=\tfrac12$; $u_{22}=5-\tfrac12\cdot2=4$. > $$L=\begin{pmatrix}1&0\\ \tfrac12&1\end{pmatrix},\ U=\begin{pmatrix}4&2\\0&4\end{pmatrix}.$$ > **Cholesky** (see [[Cholesky Decomposition]]): $g_{11}=\sqrt{4}=2$; $g_{21}=a_{21}/g_{11}=2/2=1$; $g_{22}=\sqrt{a_{22}-g_{21}^2}=\sqrt{5-1}=2$. > $$G=\begin{pmatrix}2&0\\1&2\end{pmatrix},\quad GG^\top=\begin{pmatrix}4&2\\2&5\end{pmatrix}=A.\ ✓$$ > **Link:** $u_{11}=4=g_{11}^2$ and $u_{22}=4=g_{22}^2$. Indeed Cholesky is LU where $U=D G^\top$ with $D=\mathrm{diag}(g_{ii})$, so $u_{ii}=g_{ii}^2$. This is why Cholesky needs the pivots (here $4,4$) to stay **positive**. ### Exercise 5.2 Take the same $A=\begin{pmatrix}2&3\\6&13\end{pmatrix}$ from the parent's Worked Example 1 ($L=\begin{pmatrix}1&0\\3&1\end{pmatrix},U=\begin{pmatrix}2&3\\0&4\end{pmatrix}$). Use LU to compute $A^{-1}$ by solving $A\mathbf{x}=\mathbf{e}_1$ and $A\mathbf{x}=\mathbf{e}_2$ (the columns of the identity). Confirm $\det A$ via LU too. > [!recall]- Solution > Each column of $A^{-1}$ solves $A\mathbf{x}=\mathbf{e}_j$ — reuse the **same** $L,U$. > **Column 1, $\mathbf{e}_1=(1,0)$:** forward $y_1=1$, $3\cdot1+y_2=0\Rightarrow y_2=-3$; back $4x_2=-3\Rightarrow x_2=-\tfrac34$, $2x_1+3x_2=1\Rightarrow 2x_1=1+\tfrac94=\tfrac{13}{4}\Rightarrow x_1=\tfrac{13}{8}$. > **Column 2, $\mathbf{e}_2=(0,1)$:** forward $y_1=0$, $y_2=1$; back $4x_2=1\Rightarrow x_2=\tfrac14$, $2x_1+3x_2=0\Rightarrow 2x_1=-\tfrac34\Rightarrow x_1=-\tfrac38$. > $$A^{-1}=\begin{pmatrix}\tfrac{13}{8}&-\tfrac38\\[2pt]-\tfrac34&\tfrac14\end{pmatrix}.$$ > Check via formula: $\det A=\prod u_{ii}=2\cdot4=8$, and $\frac{1}{\det A}\begin{pmatrix}13&-3\\-6&2\end{pmatrix}=\frac18\begin{pmatrix}13&-3\\-6&2\end{pmatrix}$ matches. ✓ > **Moral:** even for inversion you factor **once** and back-substitute $n$ times — never redo elimination per column. ### Exercise 5.3 Show that the matrix $$A=\begin{pmatrix}1&2\\2&4\end{pmatrix}$$ has **no** LU decomposition even with pivoting, and identify why. > [!recall]- Solution > Try Doolittle: $u_{11}=1,\ u_{12}=2$; $\ell_{21}=2/1=2$; $u_{22}=4-2\cdot2=0$. The **second** pivot is $0$, so $\det A=1\cdot0=0$ — $A$ is singular (row 2 $=2\times$ row 1). Pivoting can't help: in the first column the largest entry is $2$ (row 2), swap and you get $\begin{pmatrix}2&4\\1&2\end{pmatrix}$, then $\ell_{21}=\tfrac12$, $u_{22}=2-\tfrac12\cdot4=0$ again. The zero pivot is **structural** (rank deficiency), not an ordering accident. Contrast with Exercise 3.1, where swapping cured the problem because that $A$ was non-singular. > [!mistake] L5 trap — trusting Cholesky on a non-positive-definite matrix > Applying Cholesky to any symmetric matrix and expecting real $g_{ii}$. *Why it feels right:* the formula $g_{ii}=\sqrt{a_{ii}-\sum g_{ik}^2}$ *looks* universal. *The truth:* if $A$ is not positive-definite the quantity under the root goes $\le0$ and $g_{ii}$ becomes imaginary or zero — the algorithm **fails on purpose**, which is actually a cheap positive-definiteness test. Fix: use plain LU with [[Partial Pivoting]] for general matrices; reserve Cholesky for symmetric positive-definite ones. --- > [!recall] Wrap-up self-check (cover the answers) > - Q: In $PA=LU$, which vector do you feed to forward substitution? ::: $P\mathbf{b}$, not $\mathbf{b}$. > - Q: Why does one row swap flip the sign of $\det A$? ::: A swap is multiplication by a permutation with determinant $-1$. > - Q: How does Cholesky's diagonal relate to LU's pivots for an SPD matrix? ::: $u_{ii}=g_{ii}^2$. > - Q: A zero pivot appears — is $A$ always singular? ::: No; try pivoting first. Only structural (rank) zeros are fatal. ### Connections - [[LU decomposition (numerical)]] — the parent this page drills. - [[Gaussian Elimination]], [[Forward and Back Substitution]] — the engines behind each solve. - [[Partial Pivoting]], [[Permutation Matrices]] — the repair for zero/small pivots. - [[Determinants]], [[Cholesky Decomposition]], [[Crout Decomposition]], [[Condition Number and Numerical Stability]] — the neighbouring ideas the mastery problems touch.