You can solve a system by reducing it to Gaussian Elimination and Echelon Form and back substituting. On a computer the question becomes: how much work is that? We count flops (floating-point operations): each addition, subtraction, multiplication or division counts as one.
Key idea
Why it works
| $n$ | elimination, $\frac{2}{3}n^{3}$ | time at $10^{9}$ flops/s | back substitution, $n^{2}$ |
|---|---|---|---|
| $100$ | $6.7 \times 10^{5}$ | under a millisecond | $10^{4}$ |
| $1{,}000$ | $6.7 \times 10^{8}$ | about $0.7$ s | $10^{6}$ |
| $10{,}000$ | $6.7 \times 10^{11}$ | about 11 minutes | $10^{8}$ |
Worked example: Scaling up
- Work grows like $n^{3}$. Doubling $n$: $2^{3} = 8$ times the work, about $4$ s.
- Multiplying $n$ by 10: $10^{3} = 1000$ times, about $500$ s, over 8 minutes.
Answer: about $4$ s and about $500$ s
Worked example: Back substitution exactly
- Bottom row: $x_4 = c_4/u_{44}$, 1 division.
- Next rows: $3$, then $5$, then $7$ flops (each adds one multiply and one subtract).
- Total $1 + 3 + 5 + 7 = 16 = 4^{2}$.
Answer: $16$
Worked example: Many right-hand sides
- Redo each time: $100 \times \frac{2}{3}(1000)^{3} \approx 6.7 \times 10^{10}$ flops.
- Factor once ($PA = LU$, about $\frac{2}{3}n^{3} \approx 6.7 \times 10^{8}$), then two triangular solves per $\mathbf{b}$ ($100 \times 2n^{2} = 2 \times 10^{8}$): about $8.7 \times 10^{8}$ in all.
- About 77 times less work. This is why libraries separate "factor" from "solve".
Answer: factoring once is about 77 times cheaper
The same counting shows why computing $A^{-1}$ is a poor way to solve: forming the inverse means solving with all $n$ columns of the identity, about $2n^{3}$ flops, three times the cost of one elimination, and the product $A^{-1}\mathbf{b}$ is usually less accurate than elimination with pivoting.
Common mistake