The previous lesson ended with a question: if \(A,\mathbf{x} = \mathbf{b}\), can we "solve for" \(\mathbf{x}\) as we would with numbers? The answer is the inverse matrix, the matrix that undoes what another one does. In a 3D engine, undoing is as common as doing: going from the ship's axes to the world's and back, or from the world to the camera. In this lesson we will study the inverse, a much simpler operation called the transpose, and a privileged family of matrices—the orthogonal ones—in which the two coincide and which will underpin every rotation in the course.
The transpose
The transpose of a matrix \(A\), written \(A^T\), is obtained by swapping rows for columns: the first row of \(A\) becomes the first column of \(A^T\), and so on. The entry \(a_{ij}\) moves to position \((j, i)\).
\[ A = \begin{pmatrix} 1 & 0 & 2 \ -1 & 3 & 1 \end{pmatrix} \qquad\Longrightarrow\qquad A^T = \begin{pmatrix} 1 & -1 \ 0 & 3 \ 2 & 1 \end{pmatrix} \]
An \(m \times n\) matrix becomes an \(n \times m\) one. In a square matrix, transposing amounts to reflecting the entries across the main diagonal, which stays put.
Properties
| Property | Formula |
|---|---|
| Double transpose | \((A^T)^T = A\) |
| Sum | \((A + B)^T = A^T + B^T\) |
| Scalar | \((kA)^T = k,A^T\) |
| Product | \((AB)^T = B^T A^T\) (the order is reversed!) |
| Determinant | \(\det(A^T) = \det(A)\) |
The product rule is the one that causes the most mistakes. Let's check it with \(A = \begin{pmatrix} 1 & 2 \ 3 & 4 \end{pmatrix}\) and \(B = \begin{pmatrix} 2 & 0 \ 1 & 3 \end{pmatrix}\), whose product we have already computed: \(AB = \begin{pmatrix} 4 & 6 \ 10 & 12 \end{pmatrix}\).
\[ (AB)^T = \begin{pmatrix} 4 & 10 \ 6 & 12 \end{pmatrix} \qquad B^T A^T = \begin{pmatrix} 2 & 1 \ 0 & 3 \end{pmatrix} \begin{pmatrix} 1 & 3 \ 2 & 4 \end{pmatrix} = \begin{pmatrix} 4 & 10 \ 6 & 12 \end{pmatrix} \]
They match. By contrast, \(A^T B^T = \begin{pmatrix} 2 & 10 \ 4 & 14 \end{pmatrix}\), which is a different matrix.
In NumPy the transpose is the .T attribute:
import numpy as np
a = np.array([[1.0, 2.0], [3.0, 4.0]])
b = np.array([[2.0, 0.0], [1.0, 3.0]])
print((a @ b).T)
print(np.allclose((a @ b).T, b.T @ a.T))Symmetric matrices
A square matrix is symmetric if it equals its transpose: \(A^T = A\). Its entries mirror each other across the main diagonal (\(a_{ij} = a_{ji}\)).
\[ S = \begin{pmatrix} 5 & 3 & 2 \ 3 & 10 & 4 \ 2 & 4 & 17 \end{pmatrix} \]
Two useful facts:
- Every diagonal matrix (and the identity) is symmetric.
- For any matrix \(A\), the product \(A^T A\) is symmetric, because \((A^T A)^T = A^T (A^T)^T = A^T A\). The matrix \(S\) above is precisely \(M^T M\), with the matrix \(M\) from the determinant example.
Symmetric matrices have excellent properties that we will exploit in the lesson "Eigenvalues and Eigenvectors".
def is_symmetric(m, tolerance=1e-9):
"""True if the square matrix m equals its transpose."""
m = np.asarray(m, dtype=float)
return m.shape[0] == m.shape[1] and np.allclose(m, m.T, atol=tolerance)
m = np.array([[2.0, 0.0, 1.0],
[1.0, 3.0, 0.0],
[0.0, 1.0, 4.0]])
print(is_symmetric(m), is_symmetric(m.T @ m))The inverse matrix: definition and existence
Definition
With numbers, dividing by 5 is multiplying by \(5^{-1} = 1/5\), and \(5 \cdot 5^{-1} = 1\). With matrices, the role of 1 is played by the identity. The inverse of a square matrix \(A\) is the matrix \(A^{-1}\) that satisfies:
\[ A,A^{-1} = A^{-1} A = I \]
Geometrically, \(A^{-1}\) undoes what \(A\) does: if \(A\) takes \(\mathbf{x}\) to \(\mathbf{b}\), then \(A^{-1}\) brings \(\mathbf{b}\) back to \(\mathbf{x}\).
When it exists
Not every matrix has an inverse. The criterion is the determinant:
\[ A \text{ has an inverse} \iff \det(A) \ne 0 \]
The reason is geometric. If \(\det(A) = 0\), the matrix flattens space onto a plane or a line: many different vectors end up in the same place, and it is impossible to know which one each came from. The lost information cannot be recovered.
| \(\det(A)\) | Name | Inverse? | System \(A,\mathbf{x} = \mathbf{b}\) |
|---|---|---|---|
| \(\ne 0\) | Invertible, regular or nonsingular | Yes, and it is unique | Unique solution |
| \(= 0\) | Singular | No | None or infinitely many |
Non-square matrices have no inverse in this sense.
Inverse of a 2×2 matrix
For a 2×2 matrix there is a direct formula:
\[ A = \begin{pmatrix} a & b \ c & d \end{pmatrix} \qquad\Longrightarrow\qquad A^{-1} = \frac{1}{ad - bc} \begin{pmatrix} d & -b \ -c & a \end{pmatrix} \]
The recipe: swap the entries on the main diagonal, change the sign of the other two and divide everything by the determinant.
Example. The top-down ship basis was \(\mathbf{u}_1 = (1, 1)\), \(\mathbf{u}_2 = (-1, 1)\). The matrix with those vectors as its columns, \(U\), converts ship coordinates into world coordinates. Its determinant is 2, so:
\[ U = \begin{pmatrix} 1 & -1 \ 1 & 1 \end{pmatrix} \qquad U^{-1} = \frac{1}{2} \begin{pmatrix} 1 & 1 \ -1 & 1 \end{pmatrix} = \begin{pmatrix} 0.5 & 0.5 \ -0.5 & 0.5 \end{pmatrix} \]
\(U^{-1}\) goes the other way: it converts world coordinates into ship coordinates. In the first lesson we worked out by hand that the beacon located at \((3, 1)\) had coordinates \((2, -1)\) in the ship basis. Now it is a simple product:
\[ U^{-1} \begin{pmatrix} 3 \ 1 \end{pmatrix} = \begin{pmatrix} 0.5 \cdot 3 + 0.5 \cdot 1 \ -0.5 \cdot 3 + 0.5 \cdot 1 \end{pmatrix} = \begin{pmatrix} 2 \ -1 \end{pmatrix} \]
def inverse_2x2(m):
"""Inverse of a 2x2 matrix using the direct formula."""
det = m[0, 0] * m[1, 1] - m[0, 1] * m[1, 0]
if np.isclose(det, 0.0):
raise ValueError("Singular matrix: it has no inverse")
return np.array([[m[1, 1], -m[0, 1]],
[-m[1, 0], m[0, 0]]]) / det
u = np.array([[1.0, -1.0], [1.0, 1.0]])
print(inverse_2x2(u))
print(inverse_2x2(u) @ np.array([3.0, 1.0]))Computing the inverse by Gauss-Jordan
For larger matrices, the general method reuses Gauss-Jordan. Write the augmented matrix \((A \mid I)\) and apply elementary row operations until the left-hand part is the identity. At that point, the right-hand part is the inverse:
\[ (A \mid I) ;\longrightarrow; (I \mid A^{-1}) \]
Why does it work? Because each column of \(A^{-1}\) is the solution of a system \(A,\mathbf{x} = \mathbf{e}_i\), and we are solving all three systems at once. If a row of zeros appears in the left-hand part along the way, the matrix is singular.
Example. The thruster matrix from the previous lesson, with columns \((1,1,0)\), \((0,1,1)\) and \((1,1,1)\):
\[ \left(\begin{array}{ccc|ccc} 1 & 0 & 1 & 1 & 0 & 0 \ 1 & 1 & 1 & 0 & 1 & 0 \ 0 & 1 & 1 & 0 & 0 & 1 \end{array}\right) \]
\(R_2 \leftarrow R_2 - R_1\):
\[ \left(\begin{array}{ccc|ccc} 1 & 0 & 1 & 1 & 0 & 0 \ 0 & 1 & 0 & -1 & 1 & 0 \ 0 & 1 & 1 & 0 & 0 & 1 \end{array}\right) \]
\(R_3 \leftarrow R_3 - R_2\):
\[ \left(\begin{array}{ccc|ccc} 1 & 0 & 1 & 1 & 0 & 0 \ 0 & 1 & 0 & -1 & 1 & 0 \ 0 & 0 & 1 & 1 & -1 & 1 \end{array}\right) \]
\(R_1 \leftarrow R_1 - R_3\):
\[ \left(\begin{array}{ccc|ccc} 1 & 0 & 0 & 0 & 1 & -1 \ 0 & 1 & 0 & -1 & 1 & 0 \ 0 & 0 & 1 & 1 & -1 & 1 \end{array}\right) \qquad\Longrightarrow\qquad P^{-1} = \begin{pmatrix} 0 & 1 & -1 \ -1 & 1 & 0 \ 1 & -1 & 1 \end{pmatrix} \]
Check with the displacement toward the lighthouse, \((-8, -3, -6)\):
\[ P^{-1} \begin{pmatrix} -8 \ -3 \ -6 \end{pmatrix} = \begin{pmatrix} -3 + 6 \ 8 - 3 \ -8 + 3 - 6 \end{pmatrix} = \begin{pmatrix} 3 \ 5 \ -11 \end{pmatrix} \]
These are exactly the thrust levels we obtained by solving the system.
Computing the inverse with the adjugate matrix
There is also a closed-form formula, based on the cofactors we used for determinants:
\[ A^{-1} = \frac{1}{\det(A)},\text{adj}(A) \]
where the adjugate matrix \(\text{adj}(A)\) is the transpose of the cofactor matrix. The procedure for a 3×3 matrix:
- Compute \(\det(A)\). If it is 0, there is no inverse.
- Compute the nine cofactors \(C_{ij} = (-1)^{i+j} M_{ij}\) (the minor with its checkerboard sign).
- Form the cofactor matrix and transpose it.
- Divide by the determinant.
Example. For \(M = \begin{pmatrix} 2 & 0 & 1 \ 1 & 3 & 0 \ 0 & 1 & 4 \end{pmatrix}\) we already know that \(\det(M) = 25\). The cofactors:
| Column 1 | Column 2 | Column 3 | |
|---|---|---|---|
| Row 1 | \(+(3 \cdot 4 - 0 \cdot 1) = 12\) | \(-(1 \cdot 4 - 0 \cdot 0) = -4\) | \(+(1 \cdot 1 - 3 \cdot 0) = 1\) |
| Row 2 | \(-(0 \cdot 4 - 1 \cdot 1) = 1\) | \(+(2 \cdot 4 - 1 \cdot 0) = 8\) | \(-(2 \cdot 1 - 0 \cdot 0) = -2\) |
| Row 3 | \(+(0 \cdot 0 - 1 \cdot 3) = -3\) | \(-(2 \cdot 0 - 1 \cdot 1) = 1\) | \(+(2 \cdot 3 - 0 \cdot 1) = 6\) |
Transposing the table and dividing by 25:
\[ M^{-1} = \frac{1}{25} \begin{pmatrix} 12 & 1 & -3 \ -4 & 8 & 1 \ 1 & -2 & 6 \end{pmatrix} \]
Check of the first row of \(M,M^{-1}\): \(\tfrac{1}{25},(2 \cdot 12 + 0 \cdot (-4) + 1 \cdot 1,\ \ 2 \cdot 1 + 0 \cdot 8 + 1 \cdot (-2),\ \ 2 \cdot (-3) + 0 \cdot 1 + 1 \cdot 6) = \tfrac{1}{25},(25, 0, 0) = (1, 0, 0)\) ✓.
The 2×2 formula is this same method applied to a small matrix. In code, for any size, we use np.linalg.inv:
def inverse(m):
"""Inverse of a square matrix; clear error if it is singular."""
m = np.asarray(m, dtype=float)
if np.isclose(np.linalg.det(m), 0.0):
raise ValueError("Singular matrix: it has no inverse")
return np.linalg.inv(m)
print(inverse(m) * 25) # must be the adjugate
print(np.allclose(m @ inverse(m), np.eye(3)))Properties of the inverse
| Property | Formula |
|---|---|
| Inverse of the inverse | \((A^{-1})^{-1} = A\) |
| Product | \((AB)^{-1} = B^{-1} A^{-1}\) (the order is reversed!) |
| Transpose | \((A^T)^{-1} = (A^{-1})^T\) |
| Scalar (\(k \ne 0\)) | \((kA)^{-1} = \tfrac{1}{k} A^{-1}\) |
| Determinant | \(\det(A^{-1}) = 1 / \det(A)\) |
The product rule has an everyday explanation: you put on your socks first and then your shoes; to undo it, you take off your shoes first and then your socks. If \(AB\) means "first \(B\), then \(A\)", undoing it is "first undo \(A\), then undo \(B\)": \(B^{-1} A^{-1}\). In Module 2 this rule will be used to invert whole chains of transformations.
print(np.allclose(np.linalg.inv(a @ b), np.linalg.inv(b) @ np.linalg.inv(a)))
print(np.allclose(np.linalg.inv(a @ b), np.linalg.inv(a) @ np.linalg.inv(b)))Solving (A,\mathbf{x} = \mathbf{b}) with the inverse (and why solve is preferred in code)
If \(A\) is invertible, we multiply both sides of the equation by \(A^{-1}\) on the left:
\[ A,\mathbf{x} = \mathbf{b} ;\Longrightarrow; A^{-1} A,\mathbf{x} = A^{-1}\mathbf{b} ;\Longrightarrow; \mathbf{x} = A^{-1}\mathbf{b} \]
It is a clean formula and very useful for reasoning. In code, however, it is not a good idea to solve a system by writing np.linalg.inv(a) @ b:
np.linalg.inv(a) @ b |
np.linalg.solve(a, b) |
|
|---|---|---|
| Work | Computes the full inverse (equivalent to solving \(n\) systems) and then multiplies | Solves a single system |
| Speed | Slower | Faster |
| Accuracy | Accumulates more rounding errors | More accurate |
So when is it worth having the explicit inverse? When the same matrix is going to be applied to a huge number of vectors (for example, converting every vertex of a model from the world to the camera's axes) or when the inverse is trivial to obtain, as is the case with the orthogonal matrices we are about to see.
Ill-conditioning
Between "it has an inverse" and "it does not" there is a gray area. A matrix whose determinant is very close to zero is invertible in theory, but numerically fragile: a minuscule change in the data produces a huge change in the solution. It is said to be ill-conditioned.
Example. In the top-down view, two nearly parallel routes: \(x + z = 2\) and \(x + 1.0001,z = 2.0001\). They cross at \((1, 1)\). Suppose the sensor makes an error of one ten-thousandth in the last value:
k = np.array([[1.0, 1.0],
[1.0, 1.0001]])
print(np.linalg.solve(k, np.array([2.0, 2.0001])))
print(np.linalg.solve(k, np.array([2.0, 2.0002])))
print(round(np.linalg.cond(k)))An error of 0.0001 in one value has moved the crossing point from \((1, 1)\) to \((0, 2)\). Geometrically it makes sense: two nearly parallel lines meet at a point that "swings" wildly when one of them is nudged slightly.
np.linalg.cond returns the condition number, which measures roughly how much relative errors can be amplified. A value close to 1 is ideal; a very large one signals danger. The determinant is not a good measure of this problem (it depends on the scale of the data); the condition number is.
Orthogonal matrices
Orthonormal columns
Let's go back to the ship's orientation matrix, whose columns were the ship's axes:
\[ N = \begin{pmatrix} 0.6 & 0 & 0.8 \ 0 & 1 & 0 \ -0.8 & 0 & 0.6 \end{pmatrix} \]
Its columns have two very special geometric qualities, which we can verify with two elementary operations:
- Length 1. By the Pythagorean theorem, the length of a vector is the square root of the sum of the squares of its components. For the first column: \(0.6^2 + 0^2 + (-0.8)^2 = 0.36 + 0.64 = 1\). The same holds for the other two.
- Mutually perpendicular. Two vectors are perpendicular when the sum of the products of their components, taken one by one, is zero. For the first and third columns: \(0.6 \cdot 0.8 + 0 \cdot 0 + (-0.8) \cdot 0.6 = 0.48 - 0.48 = 0\). The other pairs also give 0.
That "sum of component-by-component products" has a name—the dot product—and, together with length, it is covered in depth in Module 3. Here we only need those two checks.
A set of vectors of length 1 that are pairwise perpendicular is called orthonormal. A square matrix whose columns are orthonormal is called an orthogonal matrix, and it is usually denoted by the letter \(Q\).
The key property: (Q^T Q = I)
Let's compute \(Q^T Q\). The \((i, j)\) entry of the product is row \(i\) of \(Q^T\)—which is column \(i\) of \(Q\)—times column \(j\) of \(Q\): precisely the sum of the products of the components of two columns.
- On the diagonal (\(i = j\)): a column with itself, that is, its length squared: 1.
- Off the diagonal (\(i \ne j\)): two different, perpendicular columns: 0.
Therefore:
\[ Q^T Q = I \qquad\Longrightarrow\qquad Q^{-1} = Q^T \]
The inverse of an orthogonal matrix is its transpose. There is no need to compute determinants or cofactors, or to apply Gauss-Jordan: just swap rows for columns, an operation that is free and has no rounding errors.
Other consequences
| Property | Meaning |
|---|---|
| \(Q^{-1} = Q^T\) | Inverting is transposing |
| \(Q,Q^T = I\) | The rows are orthonormal too |
| \(\det(Q) = \pm 1\) | It does not change volumes |
| Preserves lengths and angles | It moves objects without deforming them |
| The product of two orthogonal matrices is orthogonal | They can be chained without losing the property |
| Condition number 1 | Numerically perfect |
The determinant follows from the properties we already know: \(\det(Q^T Q) = \det(Q)^2 = \det(I) = 1\), so \(\det(Q) = \pm 1\). The sign separates two families:
- \(\det(Q) = +1\): preserves orientation. These are the rotations.
- \(\det(Q) = -1\): reverses orientation. They include a reflection (a mirror effect).
Why they will be key for rotations
Rotating a rigid object—the ship, the camera—must not stretch it, slant it, or flip it as in a mirror. Those three requirements are exactly equivalent to "orthogonal matrix with determinant \(+1\)". That is why, when we build rotation matrices in Module 2, all of them will be orthogonal, and undoing a rotation will cost nothing more than a transpose. The matrix \(N\) is, in fact, one of them (\(\det(N) = 1\), as we computed earlier).
Example in code
In the lesson "Matrices and Determinants" we saw that the antenna, located at \((1, 2, 0)\) in the ship's axes, pointed toward \((0.6, 2, -0.8)\) in the world axes. The way back is the transpose:
def is_orthogonal(m, tolerance=1e-9):
"""True if m is square and its columns are orthonormal (Q^T Q = I)."""
m = np.asarray(m, dtype=float)
if m.shape[0] != m.shape[1]:
return False
return np.allclose(m.T @ m, np.eye(m.shape[0]), atol=tolerance)
ship_orientation = np.array([[0.6, 0.0, 0.8],
[0.0, 1.0, 0.0],
[-0.8, 0.0, 0.6]])
print(is_orthogonal(ship_orientation), is_orthogonal(u))
print(ship_orientation.T @ np.array([0.6, 2.0, -0.8])) # world -> ship
print(np.allclose(ship_orientation.T, np.linalg.inv(ship_orientation)))
print(round(np.linalg.cond(ship_orientation), 6))The matrix \(U\) of the top-down basis is not orthogonal: its columns \((1, 1)\) and \((-1, 1)\) are perpendicular (\(1 \cdot (-1) + 1 \cdot 1 = 0\)), but their length is \(\sqrt{2}\), not 1. That is why its inverse did not match its transpose.
Common Mistakes and Tips
- Forgetting to reverse the order. \((AB)^T = B^T A^T\) and \((AB)^{-1} = B^{-1} A^{-1}\). Never \(A^T B^T\) or \(A^{-1} B^{-1}\).
- Confusing the inverse with the transpose. They coincide only for orthogonal matrices. Before replacing an inverse with a transpose, make sure (
is_orthogonal). - Confusing \(A^{-1}\) with "one over each entry". The inverse of a matrix is not obtained by inverting its entries one by one; in NumPy,
1 / adoes just that and is not the inverse. - Forgetting to transpose the cofactor matrix. The adjugate is the transpose of the cofactors; this is the most common slip when applying the method.
- Forgetting to divide by the determinant in the 2×2 formula or in the adjugate formula.
- Calling a matrix orthogonal when its columns are merely perpendicular. They must also have length 1.
- Using
invto solve a system. Usenp.linalg.solve. - Trusting the determinant to detect numerical problems. Use
np.linalg.cond. - Tip: check any inverse by multiplying:
np.allclose(a @ a_inv, np.eye(n)).
Exercises
Exercise 1. Let \(A = \begin{pmatrix} 4 & 7 \ 2 & 6 \end{pmatrix}\).
a) Compute \(A^{-1}\) with the 2×2 formula. b) Use it to solve \(A,\mathbf{x} = \mathbf{b}\) with \(\mathbf{b} = (15, 10)\).
Exercise 2. One of the ship's sensors uses as its basis the column vectors of
\[ Y = \begin{pmatrix} 1 & 2 & 0 \ 0 & 1 & 1 \ 1 & 0 & 1 \end{pmatrix} \]
Compute \(Y^{-1}\) by the adjugate method and check it with NumPy.
Exercise 3. Decide which of these matrices are orthogonal and, for those that are, say whether they preserve or reverse orientation:
\[ R = \begin{pmatrix} 0 & -1 & 0 \ 1 & 0 & 0 \ 0 & 0 & 1 \end{pmatrix} \qquad E = \begin{pmatrix} 0.6 & 0.8 \ 0.8 & -0.6 \end{pmatrix} \qquad G = \begin{pmatrix} 2 & 0 \ 0 & 0.5 \end{pmatrix} \]
Then, using the ship's orientation matrix \(N\): an asteroid is, relative to the ship, at the displacement \((-1.2, 1, -3.4)\) measured in the world axes. What are its coordinates in the ship's axes?
Solutions
Solution 1.
a) \(\det(A) = 4 \cdot 6 - 7 \cdot 2 = 10\). We swap the diagonal, change the sign of the other two entries and divide:
\[ A^{-1} = \frac{1}{10} \begin{pmatrix} 6 & -7 \ -2 & 4 \end{pmatrix} = \begin{pmatrix} 0.6 & -0.7 \ -0.2 & 0.4 \end{pmatrix} \]
b) \(\mathbf{x} = A^{-1}\mathbf{b} = \tfrac{1}{10},(6 \cdot 15 - 7 \cdot 10,\ -2 \cdot 15 + 4 \cdot 10) = \tfrac{1}{10},(20, 10) = (2, 1)\). Check: \(4 \cdot 2 + 7 \cdot 1 = 15\) ✓ and \(2 \cdot 2 + 6 \cdot 1 = 10\) ✓.
Solution 2. Determinant along the first row: \(\det(Y) = 1,(1 \cdot 1 - 1 \cdot 0) - 2,(0 \cdot 1 - 1 \cdot 1) + 0 = 1 + 2 = 3\).
Cofactors:
| Column 1 | Column 2 | Column 3 | |
|---|---|---|---|
| Row 1 | \(+(1 \cdot 1 - 1 \cdot 0) = 1\) | \(-(0 \cdot 1 - 1 \cdot 1) = 1\) | \(+(0 \cdot 0 - 1 \cdot 1) = -1\) |
| Row 2 | \(-(2 \cdot 1 - 0 \cdot 0) = -2\) | \(+(1 \cdot 1 - 0 \cdot 1) = 1\) | \(-(1 \cdot 0 - 2 \cdot 1) = 2\) |
| Row 3 | \(+(2 \cdot 1 - 0 \cdot 1) = 2\) | \(-(1 \cdot 1 - 0 \cdot 0) = -1\) | \(+(1 \cdot 1 - 2 \cdot 0) = 1\) |
Transposing and dividing by 3:
\[ Y^{-1} = \frac{1}{3} \begin{pmatrix} 1 & -2 & 2 \ 1 & 1 & -1 \ -1 & 2 & 1 \end{pmatrix} \]
Typical mistake: forgetting the final transposition and giving the cofactor matrix divided by 3 as the result.
Solution 3.
- \(R\): columns \((0, 1, 0)\), \((-1, 0, 0)\) and \((0, 0, 1)\). All have length 1 and are pairwise perpendicular. Orthogonal. \(\det(R) = 0 - (-1)(1 \cdot 1 - 0) + 0 = 1\): it preserves orientation (it is a rotation).
- \(E\): columns \((0.6, 0.8)\) and \((0.8, -0.6)\). Lengths: \(0.36 + 0.64 = 1\) for both. Perpendicularity: \(0.6 \cdot 0.8 + 0.8 \cdot (-0.6) = 0\). Orthogonal. \(\det(E) = -0.36 - 0.64 = -1\): it reverses orientation (it contains a reflection).
- \(G\): perpendicular columns, but with lengths 2 and 0.5. Not orthogonal (even though its determinant is 1: it stretches in one direction what it shrinks in the other).
For the asteroid, since \(N\) is orthogonal, \(N^{-1} = N^T\):
\[ N^T \begin{pmatrix} -1.2 \ 1 \ -3.4 \end{pmatrix} = \begin{pmatrix} 0.6 & 0 & -0.8 \ 0 & 1 & 0 \ 0.8 & 0 & 0.6 \end{pmatrix} \begin{pmatrix} -1.2 \ 1 \ -3.4 \end{pmatrix} = \begin{pmatrix} -0.72 + 2.72 \ 1 \ -0.96 - 2.04 \end{pmatrix} = \begin{pmatrix} 2 \ 1 \ -3 \end{pmatrix} \]
r = np.array([[0.0, -1.0, 0.0], [1.0, 0.0, 0.0], [0.0, 0.0, 1.0]])
e = np.array([[0.6, 0.8], [0.8, -0.6]])
g = np.array([[2.0, 0.0], [0.0, 0.5]])
print(is_orthogonal(r), is_orthogonal(e), is_orthogonal(g))
print(ship_orientation.T @ np.array([-1.2, 1.0, -3.4]))This is the reverse of Exercise 2 in the lesson "Matrices and Determinants", where the sensor located at \((2, 1, -3)\) in the ship's axes pointed toward \((-1.2, 1, -3.4)\) in the world.
Conclusion
The transpose swaps rows for columns; the inverse undoes the effect of a matrix and exists only when the determinant is nonzero. Both reverse the order of products: \((AB)^T = B^T A^T\) and \((AB)^{-1} = B^{-1} A^{-1}\). The inverse can be computed with the 2×2 formula, with Gauss-Jordan on \((A \mid I)\) or with the adjugate, but for solving systems in code np.linalg.solve is preferred, and it pays to keep an eye on the condition number. Orthogonal matrices—perpendicular columns of length 1—are the ideal case: their inverse is their transpose, their determinant is \(\pm 1\) and they do not deform what they move. mini3d adds is_symmetric, inverse_2x2, inverse and is_orthogonal.
We have seen matrices that deform a great deal and matrices that do not deform at all. To finish the module we will ask a subtler question: given any matrix, are there special directions that it does not rotate, but only stretches or shrinks? The answer is in the next lesson, "Eigenvalues and Eigenvectors".
