13 Linear Algebra
27 Mar 2018A large number of problems in physics can be formulated in the language of linear algebra. Not only is quantum mechanics "just" linear algebra over a complex vector space but we encounter repeatedly the case that a large number of equations have to be solved simultaneously in a form that makes them amenable to linear algebra methods.
Basic problems in linear algebra
Coupled linear equations
Given a known matrix and an -element vector , the matrix equation
\begin{gather} \mathsf{A} \mathbf{x} = \mathbf{b} \end{gather}
represents a system of coupled linear equations in the unknowns .
Eigenvalue problem
The matrix equation
\begin{gather} \mathsf{A} \mathbf{x}_i = \lambda_i \mathbf{x}_i \end{gather}
is the eigenvalue problem and a solution provides the eigenvalues and corresponding eigenvectors that satisfy the equation.
Matrix inverse
Sometimes you want to explicitly find the inverse of a matrix, ,
\begin{gather} \mathsf{A} \mathsf{A}^{-1} = \mathsf{A}^{-1} \mathsf{A} = \mathsf{1} \end{gather}
If the matrix is singular (i.e., the inverse does not exist or equivalently, ) one can still obtain a useful equivalent of the inverse, , through singular value decomposition ("SVD")
\begin{gather} \mathsf{A} = \mathsf{U} \mathsf{W} \mathsf{V}^{T} \end{gather}
where is a diagonal matrix and the other matrices are orthogonal ).1 For non-singular matrices
\begin{gather} \mathsf{A}^{-1} = \mathsf{V}\, \mathrm{diag}\left(\frac{1}{w_j}\right) \, \mathsf{U}^{T} \end{gather}
but even for singular matrices
\begin{gather} \mathbf{x} = \mathsf{V} \mathsf{W}^{-1} \mathsf{U}^{T}\, \mathbf{b} \end{gather}
will be a useful answer:
- For a matrix, values indicate precisely where is singular and very small also alert you to possible numerical problems (the solution might easily become dominated by round-off error and the matrix is said to be "ill-conditioned").
- For an overdetermined system (more equations than unknowns2) solves the least-squares fitting problem and determines the solution that minimizes the deviation in the least-squares sense.
- For an underdetermined system (fewer equations than unknowns3) it can be used to find all the vectors that span the solution space.
Numerical solution
Efficient algorithms exist to solve these problems and we will primarily use the optimized algorithms in the numpy.linalg package:
For most linear algebra work you should be using double precision because diagonalization routines and eigenvalue solvers have problems with nearly singular matrices and the better the machine precision is, the better one can distinguish a nearly singular matrix from a truly singular one.
Problem: One rod, two masses, three strings
Following Computational Physics (Chapter 6), we want to solve the problem of two masses suspended via three strings from a horizontal rod. The problem with a single mass is trivial and fully determined by the geometry. The problem with two masses is hard but by formulating it as a system of nine coupled non-linear equations in nine unknowns (the three tensions and, for convenience, we treat and as independent)
\begin{gather} \mathbf{f}(\mathbf{x}) = \mathbf{0} \end{gather}
we can use the generalization of the Newton-Raphson algorithm to dimensions to solve it. The generalization involves the computation of the "-dimensional derivative", the Jacobian matrix , and the Newton-Raphson method becomes to repeatedly solve the linear matrix problem
in order to improve the guess for the solution, , with
Class material
The Jupyter notebook 13_Linear_Algebra.ipynb contains the (life-coded) lecture notes on basic linear algebra. Skeleton code for in-class exercises can be found in 13_Linear_Algebra-students-1.ipynb.4
To get started on the 1 rod/2 masses/3 strings problem work with the notebook 13_String_Problem-Students.ipynb. The full solution can be found in 13_String_Problem.ipynb.
The notebook 13_SVD.ipynb shows the principles and applications of SVD (with skeleton code in 13_SVD-Students-1.ipynb).
Additional resources:
- Computational Physics: Chapter 6
- 13_linear_algebra notebook (PDF)
- Lecture notes for the 1 rod/2 masses/3 strings problem (PDF) and solution for the problem (PDF)
- 13_SVD notebook (PDF)
- Numerical Recipes in C, WH Press, SA Teukolsky, WT Vetterling, BP Flannery. 2nd ed, 2002. Cambridge University Press. Chapter 2.
Footnotes
-
For singular matrices, some elements on the diagonal of are zero so in order to form the pseudo-inverse these elements have to be augmented and replaced by zero in . ↩
-
The overdetermined system has more equations than unknowns , , i.e., the solution vector has elements but the matrix now has the shape . ↩
-
The underdetermined system does not typically have a unique solution because is has . ↩
-
As usual,
git pull
the resources repository to get a local copy of the notebook. Then copy the notebook into your work directory in order to complete the exercises. ↩