Linear Algebra Review & Costs
Cost analysis, basic solution schemes, and why we never invert a matrix.
🎯 Goals
- 1 Recall linear algebra (ouch!).
- 2 Cost analysis of basic operations.
- 3 Identify basic solution schemes to systems.
Why this matters
- Matrix problems arise in graphics, design, information sciences.
- BLAS (Basic Linear Algebra Subprograms) is the standard.
- Simple systems set the stage for avoiding errors and large costs.
Prerequisite Warning
Linear Algebra is a prerequisite! You should be comfortable with Appendix D.1 and D.2 in the textbook.
The Matrix Inverse
Let $A$ be a square (\matdim{n}{n}) matrix. The inverse $A^{-1}$ satisfies:
Formal Solution to $Ax=b$
🚫 STOP!
Do not compute the solution to $Ax=b$ by finding $A^{-1}$ and multiplying!
We see: $x = A^{-1}b$.
We do: Solve $Ax=b$ by Gaussian elimination.
🧠 Knowledge Check +10 XP
Why do we avoid computing the matrix inverse explicitly to solve a system?
Singularity & Solution Existence
Singular Matrix Properties
If $A$ is singular:
- Columns/Rows are linearly dependent.
- $\rank{A} < n$.
- $\det(A) = 0$.
- $A^{-1}$ does not exist.
- Solution may not exist or is not unique.
Requirement for Unique Solution
The solution to $Ax=b$ exists and is unique for any $b$ if and only if:
Three Situations for $Ax=b$
$A$ is Nonsingular.
$\Rightarrow x=\begin{bmatrix}1/2\\2\end{bmatrix}$
$A$ singular, $b \in Range(A)$.
$\Rightarrow x=\begin{bmatrix}1/2\\\alpha\end{bmatrix}$
$A$ singular, $b \notin Range(A)$.
The Cost of Solving
Complexity grows rapidly with dimensions. Consider solving coupled equations on a grid.
1D Grid
$n$ points. Matrix has ~ $3n$ nonzeros. Tridiagonal (Easy).
2D Grid
$n^2$ points. ~$9n^2$ nonzeros. $n$-banded (Harder).
3D Grid
$n^3$ points. ~$27n^3$ nonzeros. $n^2$-banded (Yikes!).
Storage Explosion
| Dim | Unknowns | Storage |
|---|---|---|
| 1D | $n$ | $3n$ |
| 2D | $n^2$ | $9n^2$ |
| 3D | $n^3$ | $27n^3$ |
Real World Complexity
Complexity Analysis (Big-O)
$\mO(g(n))$
Asymptotic Upper Bound
$f(n) \leq c g(n)$
$\Omega(g(n))$
Asymptotic Lower Bound
$c g(n) \leq f(n)$
$\Theta(g(n))$
Asymptotic Tight Bound
$\mO(g(n)) \cap \Omega(g(n))$
BLAS & Operations
BLAS (Basic Linear Algebra Subprograms) defines standard interfaces.
Vector-Vector
$y \leftarrow \alpha x + y$
Cost: $\mO(n)$
Matrix-Vector
$y \leftarrow \alpha A x + \beta y$
Cost: $\mO(n^2)$
Matrix-Matrix
$C \leftarrow \alpha A B + \beta C$
Cost: $\mO(n^3)$
Matrix-Vector Multiplication Algorithm
$n^2$ multiplies, $n^2$ additions $\rightarrow \mO(n^2)$
Matrix-Matrix Multiplication Algorithm
$n^3$ multiplies, $n^3$ additions $\rightarrow \mO(n^3)$
Gaussian Elimination Schemes
Solving Diagonal Systems
If $A$ is diagonal, the system decouples:
Cost: $\mO(n)$ FLOPS (Cheap!)
Solving Triangular Systems
Lower Triangular ($Ly=b$): Use Forward Substitution.
$x_i = (b_i - \sum l_{ij}x_j) / l_{ii}$
Upper Triangular ($Ux=c$): Use Backward Substitution.
Forward Substitution Algo
Cost Analysis
Total FLOPS $\approx \sum_{j=1}^n 2j = n(n+1) \approx n^2$.
$\mO(n^2)$ FLOPS
🧠 Final Challenge +20 XP
Which operation is the most computationally expensive for large $n$?
Interactive Playground
Experiment with matrix operations and timing. You can run MATLAB code via Octave Online or Python code directly in your browser.
Python (Client-Side)
Loading Python environment...