---
title: Positive definite matrices
heading: Bowls, energy and the cheapest factorization
eyebrow: A7 · Lesson 42 · Positive definite matrices
xp: 40
---

::: hook
Set any voltages you like on the nodes of a resistor network and it dissipates power, never less than zero, and exactly zero only if every node is at ground. That simple fact makes its conductance matrix **positive definite**, the most useful property a symmetric matrix can have. Positive definite systems always have a unique solution, can be solved with half the work of ordinary elimination, and are the matrices behind every minimization problem: the solution of $S\mathbf{x} = \mathbf{b}$ is the bottom of a bowl.
:::

::: play
- The shading is $f(\mathbf{x}) = \frac{1}{2}\mathbf{x}^TS\mathbf{x} - \mathbf{b}^T\mathbf{x}$ with $S = \begin{bmatrix}a & c\\c & d\end{bmatrix}$ and $\mathbf{b} = (1, 0.5)$. The contours are its level curves.
- While $S$ is positive definite the surface is a bowl, and the dot at its lowest point is the solution of $S\mathbf{x} = \mathbf{b}$.
- Raise $|c|$ past $\sqrt{ad}$. What happens to the bowl, and to its bottom?
:::
:::

```sim plot
view: flow
x: x = -2..2
y: y = -2..2
slider: a = 0.5..3 step 0.1 = 2
slider: c = -2.5..2.5 step 0.1 = 0.5
slider: d = 0.5..3 step 0.1 = 1
shade: 0.5*(a*x^2 + 2*c*x*y + d*y^2) - x - 0.5*y | contours: 14
dot: (d*1 - c*0.5)/(a*d - c^2), (a*0.5 - c*1)/(a*d - c^2) | label: solution of Sx = b
readout: second pivot = d - c^2/a | digits: 3
readout: det S = a*d - c^2 | digits: 3
```

::: predict
## $S = \begin{bmatrix}1 & 2\\2 & 1\end{bmatrix}$ has positive entries. Is it positive definite?

- [ ] Yes: all entries are positive
- [x] No: its eigenvalues are 3 and $-1$
- [ ] Yes: it's symmetric
- [ ] It depends on $\mathbf{x}$

::: reveal
No. Its eigenvalues are $1 \pm 2$, and $-1$ is negative: along $(1, -1)$, $\mathbf{x}^TS\mathbf{x} = 1 - 4 + 1 = -2$. Positive entries aren't the test. The surface $\mathbf{x}^TS\mathbf{x}$ is a saddle, not a bowl, so it has no lowest point.
:::
:::

::: nameit
## Five equivalent tests

A symmetric matrix $S$ is **positive definite** when any one of these holds (and then they all do):

1. All eigenvalues are positive.
2. All pivots are positive (elimination without row swaps).
3. All upper-left determinants are positive.
4. $\mathbf{x}^TS\mathbf{x} > 0$ for every nonzero $\mathbf{x}$: the energy test.
5. $S = A^TA$ for some $A$ with independent columns.

For 2 × 2, $\begin{bmatrix}a & c\\c & d\end{bmatrix}$ is positive definite exactly when $a > 0$ and $ad - c^2 > 0$. With $\ge$ instead of $>$ the matrix is **positive semidefinite**.

## Minimization

If $S$ is positive definite, $f(\mathbf{x}) = \frac{1}{2}\mathbf{x}^TS\mathbf{x} - \mathbf{b}^T\mathbf{x}$ is a bowl with a single lowest point, where its gradient $S\mathbf{x} - \mathbf{b}$ is zero:

$$\text{minimize } f \iff S\mathbf{x} = \mathbf{b}, \qquad f_{\min} = -\tfrac{1}{2}\mathbf{b}^T\mathbf{x}^*$$

Many physical systems settle into their lowest-energy state, and their equilibrium equations are positive definite. In a resistor network, the currents divide so as to minimize the total power dissipated for the given injected currents (Maxwell's minimum heat theorem).

## Resistor networks

The power a grounded network dissipates at node voltages $\mathbf{v}$ is $\mathbf{v}^TG\mathbf{v} = \sum_{\text{branches}}g_k(\Delta v_k)^2$, positive unless every node is at ground. So $G = A^TCA$ is positive definite: test 5 with $A$ the grounded incidence matrix.

## Cholesky factorization

A positive definite $S$ factors as $S = LL^T$, with $L$ lower triangular and positive diagonal. It needs about $\frac{n^3}{6}$ operations, half of LU, and no row swaps. Circuit simulators and finite-element codes use it whenever the matrix allows. For 2 × 2:

$$L = \begin{bmatrix}\sqrt a & 0\\c/\sqrt a & \sqrt{d - c^2/a}\end{bmatrix}$$
:::

::: example
## Test $S = \begin{bmatrix}2 & -1 & 0\\-1 & 2 & -1\\0 & -1 & 2\end{bmatrix}$.

::: solution
1. **Pivots.**
   $$2, \quad 2 - \tfrac{1}{2} = \tfrac{3}{2}, \quad 2 - \tfrac{2}{3} = \tfrac{4}{3}$$
   All positive, so it's positive definite.
2. **Upper-left determinants.** They are $2$, $3$ and $4$, the pivots' running products.
3. **Where it comes from.** This matrix is the conductance matrix of a chain of equal resistors with both ends grounded.

**Answer:** $S$ is positive definite, since its pivots 2, $\frac32$ and $\frac43$ are all positive.
:::
:::

::: example
## Minimize $f(x, y) = x^2 + xy + y^2 - x$.

::: solution
1. **Match the standard form.** It's $\frac{1}{2}\mathbf{x}^TS\mathbf{x} - \mathbf{b}^T\mathbf{x}$ with
   $$S = \begin{bmatrix}2 & 1\\1 & 2\end{bmatrix}, \quad \mathbf{b} = (1, 0)$$
2. **Solve $S\mathbf{x} = \mathbf{b}$.** $S$ is positive definite (pivots 2 and 1.5), so the minimum is at
   $$\mathbf{x}^* = \left(\tfrac{2}{3}, -\tfrac{1}{3}\right)$$
3. **Minimum value.**
   $$\begin{aligned} f_{\min} &= -\tfrac{1}{2}\mathbf{b}^T\mathbf{x}^* \\ &= -\tfrac{1}{3} \end{aligned}$$
4. **Check directly.**
   $$\begin{aligned} &\tfrac{4}{9} - \tfrac{2}{9} + \tfrac{1}{9} - \tfrac{2}{3} \\ &= -\tfrac{1}{3} \end{aligned}$$

**Answer:** the minimum is $-\frac13$, at $\left(\frac23, -\frac13\right)$.
:::
:::

::: example
## For which $c$ is $S = \begin{bmatrix}2 & c\\c & 2\end{bmatrix}$ positive definite?

::: solution
1. **First pivot.** The first pivot, 2, is positive.
2. **Determinant.** It must be positive too:
   $$4 - c^2 > 0$$
   so $|c| < 2$. Equivalently, the eigenvalues $2 \pm c$ must both be positive.
3. **The edge case.** At $c = 2$ the matrix is only semidefinite: $\mathbf{x} = (1, -1)$ gives $\mathbf{x}^TS\mathbf{x} = 0$, a flat valley in the bowl.
4. **In a circuit.** A conductance matrix behaves the same way: it's definite as long as some path leads to ground.

**Answer:** $S$ is positive definite for $|c| < 2$.
:::
:::

::: check
given: a = 2 | 4; d = 3 | 8
answer: sqrt(a*d)
tolerance: 0.5%

## $\begin{bmatrix}\given{a} & c\\c & \given{d}\end{bmatrix}$ is positive definite for $|c|$ below what value?

::: right
Right. It needs $ad - c^2 > 0$: $|c| < \sqrt{ad}$ = {answer}.
:::

::: misses
- [a*d] The condition is on $c^2$, so take a square root.
- [(a + d)/2] The test is the determinant, $ad - c^2$.
- [any] Not yet. Set the determinant to zero.
:::
:::

::: check
given: a = 2 | 4; c = 2 | -3; d = 5 | 6
answer: d - c^2/a
tolerance: 0.5%

## What is the second pivot of $\begin{bmatrix}\given{a} & \given{c}\\\given{c} & \given{d}\end{bmatrix}$?

::: right
Right. $d - \frac{c}{a}c = d - \frac{c^2}{a}$ = {answer}.
:::

::: misses
- [d - c/a] The multiplier $c/a$ multiplies the entry $c$.
- [d] Subtract the multiple of row 1.
- [any] Not yet. Eliminate below the first pivot.
:::
:::

::: check
given: s1 = 2 | 4; s2 = 1 | 5; b1 = 2 | 6; b2 = 3 | -2
answer: -0.5*(b1^2/s1 + b2^2/s2)
tolerance: 0.5%

## What is the minimum value of $f = \frac{1}{2}(\given{s1}x^2 + \given{s2}y^2) - \given{b1}x - \given{b2}y$?

::: right
Right. The bottom is at $x = b_1/s_1$, $y = b_2/s_2$, and $f_{\min} = -\frac{1}{2}\mathbf{b}^T\mathbf{x}^*$ = {answer}.
:::

::: misses
- [-(b1^2/s1 + b2^2/s2)] Include the $\frac{1}{2}$: $f_{\min} = -\frac{1}{2}\mathbf{b}^T\mathbf{x}^*$.
- [0] The bowl's bottom is below zero when $\mathbf{b} \ne \mathbf{0}$.
- [any] Not yet. Find $\mathbf{x}^* = S^{-1}\mathbf{b}$, then evaluate $f$.
:::
:::

::: check
kind: choice

## Which matrix is positive definite?

- [x] $\begin{bmatrix}3 & 2\\2 & 2\end{bmatrix}$
- [ ] $\begin{bmatrix}1 & 2\\2 & 1\end{bmatrix}$
- [ ] $\begin{bmatrix}2 & 3\\3 & 4\end{bmatrix}$
- [ ] $\begin{bmatrix}-1 & 0\\0 & -2\end{bmatrix}$

::: right
Right. $3 > 0$ and $3 \times 2 - 2^2 = 2 > 0$.
:::

::: misses
- [2] Determinant $1 - 4 = -3$.
- [3] Determinant $8 - 9 = -1$.
- [4] Negative eigenvalues: it's negative definite.
- [any] Check $a > 0$ and $ad - c^2 > 0$.
:::
:::

::: check
given: a = 4 | 9; c = 2 | 3; d = 5 | 10
answer: sqrt(d - c^2/a)
tolerance: 0.5%

## In the Cholesky factor $L$ of $\begin{bmatrix}\given{a} & \given{c}\\\given{c} & \given{d}\end{bmatrix}$, what is $L_{22}$?

::: right
Right. $\sqrt{d - c^2/a}$ = {answer}: the square root of the second pivot.
:::

::: misses
- [d - c^2/a] Take the square root: $LL^T$ multiplies $L_{22}$ by itself.
- [sqrt(d)] Remove the part already accounted for by $L_{21}^2 = c^2/a$.
- [any] Not yet. $L_{22}^2 = d - L_{21}^2$.
:::
:::

::: check
given: n = 3 | 5 | 10
answer: n + 1

## What is the determinant of the $n \times n$ matrix with 2 on the diagonal and $-1$ just above and below it, for $n$ = {n}?

::: right
Right. The pivots are $\frac{2}{1}, \frac{3}{2}, \ldots, \frac{n + 1}{n}$, which multiply to $n + 1$ = {answer}.
:::

::: misses
- [2^n] The off-diagonal entries reduce each pivot below 2.
- [n] One more: the product telescopes to $n + 1$.
- [any] Not yet. Find the first few pivots and multiply.
:::
:::

::: check
kind: parts
given: a = 2 | 3; b = 0.5 | 1.5

## Test $S = \begin{bmatrix}\given{a} & \given{b}\\\given{b} & 1\end{bmatrix}$.

::: part
answer: 1 - b^2/a
tolerance: 0.5%

### What is its second pivot?

::: misses
- [1 - b/a] The multiplier is $b/a$, and it multiplies $b$.
- [any] $1 - \frac{b}{a}b$.
:::
:::

::: part
answer: sqrt(a)
tolerance: 0.5%

### What is the largest off-diagonal entry $c$ for which $\begin{bmatrix}\given{a} & c\\c & 1\end{bmatrix}$ is positive definite?

::: misses
- [a] The determinant $a - c^2$ must be positive.
- [any] Need $a \cdot 1 - c^2 > 0$.
:::
:::
:::

::: check
kind: derivation
vars: a = 1..4, b = -1..1, c = 2..5

## Find the Cholesky factor $L$ of $\begin{bmatrix}a & b\\b & c\end{bmatrix} = LL^T$.

::: step
answer: sqrt(a)

### What is $L_{11}$?
:::

::: step
answer: b/sqrt(a)

### What is $L_{21}$?
:::

::: step
answer: sqrt(c - b^2/a)

### What is $L_{22}$?
:::

::: right
Right. The square root under $L_{22}$ is real exactly when the matrix is positive definite.
:::
:::

::: explain
## Why is the conductance matrix of a grounded resistor network positive definite?

::: model
The power dissipated at node voltages $\mathbf{v}$ is $\mathbf{v}^TG\mathbf{v}$, which adds up $g_k(\Delta v_k)^2$ over every resistor. Each term is at least zero, so the total is never negative. It can only be zero if every resistor has zero voltage across it, which means every node is at the same voltage as its neighbors, and since some node is grounded, all of them are at zero. So $\mathbf{v}^TG\mathbf{v} > 0$ for every nonzero $\mathbf{v}$, which is the energy test for positive definiteness.
:::
:::

::: practice

::: check
given: a = 3 | 5; c = 1 | 2
answer: c/sqrt(a)
tolerance: 0.5%

## In the Cholesky factor of $\begin{bmatrix}\given{a} & \given{c}\\\given{c} & 7\end{bmatrix}$, what is $L_{21}$?

::: misses
- [c/a] Divide by $L_{11} = \sqrt{a}$.
- [any] $c/\sqrt{a}$.
:::
:::

::: check
given: s = 2 | 4; b = 3 | 8
answer: b/s
tolerance: 0.5%

## Where is the minimum of $f(x) = \frac{1}{2}\given{s}x^2 - \given{b}x$?

::: misses
- [s/b] Set $f' = sx - b = 0$.
- [any] $sx = b$.
:::
:::

::: check
given: a = 2 | 3; c = 1 | 2; d = 4 | 6
answer: a*d - c^2

## What is the second upper-left determinant of $\begin{bmatrix}\given{a} & \given{c}\\\given{c} & \given{d}\end{bmatrix}$?

::: misses
- [any] The determinant of the whole 2 × 2.
:::
:::
:::
