Math for Causal Inference

Day 19. Inverses, Determinants & Systems of Equations

Solving Ax = b, what the determinant measures, and why nearly singular systems are fragile.

Video coming soon
Learning outcomes
  • ●Compute 2×2 and 3×3 determinants and the inverse of a 2×2 matrix.
  • ●Prove the main inverse rules and connect a zero determinant to rank deficiency.
  • ●Solve market-equilibrium and input–output models as linear systems and do comparative statics.
  • ●Explain ill-conditioning and why it makes estimates sensitive to small data changes.
2-HOUR SESSION PLAN
Theory 25′Warm-up (1–5) 20′Proofs (6–10) 35′Applied (11–15) 25′Python & Lab 15′
Colab notebook (.ipynb) Jump to the simulator

Theory

Linear systems

A system of nn equations in nn unknowns is Ax=bAx = b. If AA has an inverse A−1A^{-1} (with AA−1=A−1A=IAA^{-1} = A^{-1}A = I), the unique solution is x=A−1bx = A^{-1}b.

The 2×2 case

A=(abcd),det⁡A=ad−bc,A−1=1ad−bc(d−b−ca).A = \begin{pmatrix}a & b\\c & d\end{pmatrix}, \qquad \det A = ad - bc, \qquad A^{-1} = \frac{1}{ad - bc}\begin{pmatrix}d & -b\\-c & a\end{pmatrix}.

Determinants

For 3×3 matrices, expand along the first row (cofactor expansion):

det⁡A=a11∣a22a23a32a33∣−a12∣a21a23a31a33∣+a13∣a21a22a31a32∣.\det A = a_{11}\begin{vmatrix}a_{22} & a_{23}\\a_{32} & a_{33}\end{vmatrix} - a_{12}\begin{vmatrix}a_{21} & a_{23}\\a_{31} & a_{33}\end{vmatrix} + a_{13}\begin{vmatrix}a_{21} & a_{22}\\a_{31} & a_{32}\end{vmatrix}.

Key facts:

  • ∣det⁡A∣|\det A| is the factor by which AA scales areas (volumes); the sign says whether it flips orientation.
  • det⁡(AB)=det⁡Adet⁡B\det(AB) = \det A\det B, det⁡(A⊤)=det⁡A\det(A^{\top}) = \det A, det⁡(A−1)=1/det⁡A\det(A^{-1}) = 1/\det A.
  • AA is invertible   ⟺  det⁡A≠0  ⟺  \iff \det A \ne 0 \iff full rank   ⟺  Ax=0\iff Ax = 0 only for x=0x = 0.

Inverse rules

(AB)−1=B−1A−1,(A⊤)−1=(A−1)⊤,(cA)−1=c−1A−1.(AB)^{-1} = B^{-1}A^{-1}, \qquad (A^{\top})^{-1} = (A^{-1})^{\top}, \qquad (cA)^{-1} = c^{-1}A^{-1}.

In practice, software never forms A−1A^{-1} to solve a system; it uses elimination (LU or QR factorisations), which is faster and more accurate.

Conditioning

If det⁡A\det A is close to zero relative to the size of the entries, AA is ill-conditioned: tiny changes in bb or AA produce large changes in xx. The condition number (ratio of largest to smallest singular value) measures this; Day 21 relates it to eigenvalues of X⊤XX^{\top}X.

Part 1 · Warm-up

Exercise 1 · A determinant

Compute det⁡(3124)\det\begin{pmatrix}3 & 1\\2 & 4\end{pmatrix}.

Show solution

3×4−1×2=103 \times 4 - 1 \times 2 = 10.

Exercise 2 · An inverse

Find the inverse of the matrix in Exercise 1 and check it.

Show solution

A−1=110(4−1−23)A^{-1} = \frac{1}{10}\begin{pmatrix}4 & -1\\-2 & 3\end{pmatrix}. Check: AA−1=110(12−2−3+38−8−2+12)=IAA^{-1} = \frac{1}{10}\begin{pmatrix}12 - 2 & -3 + 3\\8 - 8 & -2 + 12\end{pmatrix} = I.

Exercise 3 · Solving a system

Solve 3x+y=93x + y = 9, 2x+4y=162x + 4y = 16.

Show solution

Step 1. Write the system as A(x,y)⊤=(9,16)⊤A(x, y)^{\top} = (9, 16)^{\top} with A−1=110(4−1−23)A^{-1} = \frac{1}{10}\begin{pmatrix}4 & -1\\-2 & 3\end{pmatrix} (Exercise 2).

Step 2. x=110(4⋅9−1⋅16)=2010=2x = \frac{1}{10}(4 \cdot 9 - 1 \cdot 16) = \frac{20}{10} = 2.

Step 3. y=110(−2⋅9+3⋅16)=3010=3y = \frac{1}{10}(-2 \cdot 9 + 3 \cdot 16) = \frac{30}{10} = 3.

Step 4. Check: 3(2)+3=93(2) + 3 = 9 and 2(2)+4(3)=162(2) + 4(3) = 16. ✓

Answer: (x,y)=(2,3)(x, y) = (2, 3).

Exercise 4 · A 3×3 determinant

Compute det⁡(201132111)\det\begin{pmatrix}2 & 0 & 1\\1 & 3 & 2\\1 & 1 & 1\end{pmatrix}. Is the matrix invertible?

Show solution

2(3−2)−0+1(1−3)=2−2=02(3 - 2) - 0 + 1(1 - 3) = 2 - 2 = 0. Singular: not invertible. (Column 3 = ½ column 1 + ½ column 2.)

Exercise 5 · Area scaling

A=(2103)A = \begin{pmatrix}2 & 1\\0 & 3\end{pmatrix} maps the unit square to a parallelogram. What is its area?

Show solution

∣det⁡A∣=6|\det A| = 6. The images of (1,0)(1, 0) and (0,1)(0, 1) are (2,0)(2, 0) and (1,3)(1, 3): base 2, height 3.

Part 2 · Proofs

Exercise 6 · Inverse of a product

Prove (AB)−1=B−1A−1(AB)^{-1} = B^{-1}A^{-1} for invertible AA and BB.

Show solution

(AB)(B−1A−1)=A(BB−1)A−1=AA−1=I(AB)(B^{-1}A^{-1}) = A(BB^{-1})A^{-1} = AA^{-1} = I, and similarly in the other order. Inverses are unique, so this is (AB)−1(AB)^{-1}.

Exercise 7 · Inverse of a transpose

Prove (A⊤)−1=(A−1)⊤(A^{\top})^{-1} = (A^{-1})^{\top}. Conclude that the inverse of a symmetric matrix is symmetric.

Show solution

Step 1. A⊤(A−1)⊤=(A−1A)⊤=I⊤=IA^{\top}(A^{-1})^{\top} = (A^{-1}A)^{\top} = I^{\top} = I.

Step 2. If A=A⊤A = A^{\top}, then A−1=(A⊤)−1=(A−1)⊤A^{-1} = (A^{\top})^{-1} = (A^{-1})^{\top}.

Step 3. So (X⊤X)−1(X^{\top}X)^{-1} is symmetric, as a covariance matrix must be.

Exercise 8 · The 2×2 formula

Verify that the 2×2 inverse formula satisfies AA−1=IAA^{-1} = I.

Show solution

(abcd)(d−b−ca)=(ad−bc00ad−bc)\begin{pmatrix}a & b\\c & d\end{pmatrix}\begin{pmatrix}d & -b\\-c & a\end{pmatrix} = \begin{pmatrix}ad - bc & 0\\0 & ad - bc\end{pmatrix}. Dividing by ad−bcad - bc gives II; this is possible only if ad−bc≠0ad - bc \ne 0.

Exercise 9 · Determinant of the inverse

Using det⁡(AB)=det⁡Adet⁡B\det(AB) = \det A\det B, prove det⁡(A−1)=1/det⁡A\det(A^{-1}) = 1/\det A.

Show solution

1=det⁡I=det⁡(AA−1)=det⁡A⋅det⁡(A−1)1 = \det I = \det(AA^{-1}) = \det A\cdot\det(A^{-1}). So det⁡A≠0\det A \ne 0 and det⁡(A−1)=1/det⁡A\det(A^{-1}) = 1/\det A.

Exercise 10 · Unique, none, or infinitely many

Show that if AA is invertible, Ax=bAx = b has exactly one solution. Give a singular example with no solution and one with infinitely many.

Show solution

Step 1 (existence). x=A−1bx = A^{-1}b works: A(A−1b)=bA(A^{-1}b) = b.

Step 2 (uniqueness). If Ax1=Ax2=bAx_1 = Ax_2 = b, then A(x1−x2)=0A(x_1 - x_2) = 0; multiply by A−1A^{-1} to get x1−x2=0x_1 - x_2 = 0.

Step 3 (singular, no solution). A=(1111)A = \begin{pmatrix}1 & 1\\1 & 1\end{pmatrix}, b=(1,2)b = (1, 2): the equations x+y=1x + y = 1 and x+y=2x + y = 2 are parallel lines.

Step 4 (singular, infinitely many). Same AA with b=(1,1)b = (1, 1): both equations are the line x+y=1x + y = 1. ■\blacksquare

Part 3 · Applied

Exercise 11 · Market equilibrium

Demand Q=100−2P+0.5YQ = 100 - 2P + 0.5Y and supply Q=20+3PQ = 20 + 3P, with income Y=40Y = 40. Write the system as A(Q,P)⊤=bA(Q, P)^{\top} = b and solve it.

Show solution

Step 1. Substitute Y=40Y = 40: demand is Q=120−2PQ = 120 - 2P, i.e. Q+2P=120Q + 2P = 120. Supply is Q−3P=20Q - 3P = 20.

Step 2. Matrix form:

(121−3)(QP)=(12020),det⁡A=(1)(−3)−(2)(1)=−5.\begin{pmatrix}1 & 2\\1 & -3\end{pmatrix}\begin{pmatrix}Q\\P\end{pmatrix} = \begin{pmatrix}120\\20\end{pmatrix}, \qquad \det A = (1)(-3) - (2)(1) = -5.

Step 3. Inverse: A−1=1−5(−3−2−11)A^{-1} = \frac{1}{-5}\begin{pmatrix}-3 & -2\\-1 & 1\end{pmatrix}.

Step 4. Q=(−3)(120)+(−2)(20)−5=−400−5=80Q = \frac{(-3)(120) + (-2)(20)}{-5} = \frac{-400}{-5} = 80 and P=(−1)(120)+(1)(20)−5=−100−5=20P = \frac{(-1)(120) + (1)(20)}{-5} = \frac{-100}{-5} = 20.

Answer: equilibrium price 20 and quantity 80.

Exercise 12 · Comparative statics

In Exercise 11, find dP/dYdP/dY and dQ/dYdQ/dY.

Show solution

Step 1. Income enters only the right-hand side: b=(100+0.5Y,  20)⊤b = (100 + 0.5Y,\; 20)^{\top}, so db/dY=(0.5,0)⊤db/dY = (0.5, 0)^{\top}.

Step 2. (Q,P)⊤=A−1b(Q, P)^{\top} = A^{-1}b, hence d(Q,P)⊤/dY=A−1(0.5,0)⊤d(Q, P)^{\top}/dY = A^{-1}(0.5, 0)^{\top}.

Step 3. Using A−1A^{-1} from Exercise 11: 1−5((−3)(0.5),  (−1)(0.5))=1−5(−1.5,−0.5)=(0.3,0.1)\frac{1}{-5}\big((-3)(0.5),\; (-1)(0.5)\big) = \frac{1}{-5}(-1.5, -0.5) = (0.3, 0.1).

Answer: dQ/dY=0.3dQ/dY = 0.3 and dP/dY=0.1dP/dY = 0.1: a $1 rise in income raises quantity by 0.3 and price by 0.1.

Exercise 13 · An ill-conditioned diet plan

A school-meals programme mixes two foods, xx and yy (kg per pupil per week), whose nutrient contents are almost identical. It must hit a calorie target and a protein target:

x+y=2,x+1.001 y=2.001.x + y = 2, \qquad x + 1.001\,y = 2.001.

Solve the system. Then suppose the protein target is revised to 2.002 and solve again.

Show solution

Step 1. Subtract the first equation from the second: 0.001 y=0.001⇒y=10.001\,y = 0.001 \Rightarrow y = 1, so x=1x = 1.

Step 2. With the revised target: 0.001 y=0.002⇒y=20.001\,y = 0.002 \Rightarrow y = 2, so x=0x = 0.

Step 3. Why: det⁡A=1.001−1=0.001\det A = 1.001 - 1 = 0.001; the two lines are almost parallel (condition number ≈ 4,000).

Answer: a 0.05% change in one target switches the plan from 1 kg of each food to 2 kg of one and none of the other. Collinear regressors make β^\hat\beta fragile in exactly this way.

Exercise 14 · Leontief input–output

Two sectors use each other's output: A=(0.20.30.40.1)A = \begin{pmatrix}0.2 & 0.3\\0.4 & 0.1\end{pmatrix}, final demand d=(100,50)d = (100, 50). Gross output solves x=Ax+dx = Ax + d. Find xx.

Show solution

Step 1. x=Ax+d  ⟺  (I−A)x=dx = Ax + d \iff (I - A)x = d.

Step 2. I−A=(0.8−0.3−0.40.9)I - A = \begin{pmatrix}0.8 & -0.3\\-0.4 & 0.9\end{pmatrix}, with determinant 0.8(0.9)−(−0.3)(−0.4)=0.72−0.12=0.600.8(0.9) - (-0.3)(-0.4) = 0.72 - 0.12 = 0.60.

Step 3. (I−A)−1=10.6(0.90.30.40.8)(I - A)^{-1} = \frac{1}{0.6}\begin{pmatrix}0.9 & 0.3\\0.4 & 0.8\end{pmatrix}.

Step 4. x1=0.9(100)+0.3(50)0.6=1050.6=175x_1 = \frac{0.9(100) + 0.3(50)}{0.6} = \frac{105}{0.6} = 175 and x2=0.4(100)+0.8(50)0.6=800.6≈133.3x_2 = \frac{0.4(100) + 0.8(50)}{0.6} = \frac{80}{0.6} \approx 133.3.

Answer: gross output (175, 133.3): delivering 100 and 50 to final users requires extra production for intermediate use.

Exercise 15 · The IV estimator solves a system

With one instrument zz and one regressor xx (both centred), the IV condition is z⊤(y−xβ)=0z^{\top}(y - x\beta) = 0. Solve for β\beta, and evaluate it when Cov⁡^(z,y)=0.6\widehat{\operatorname{Cov}}(z, y) = 0.6 and Cov⁡^(z,x)=0.3\widehat{\operatorname{Cov}}(z, x) = 0.3.

Show solution

Step 1. Expand the condition: z⊤y−z⊤x β=0z^{\top}y - z^{\top}x\,\beta = 0.

Step 2. Solve: β^=(z⊤x)−1z⊤y\hat\beta = (z^{\top}x)^{-1}z^{\top}y. Dividing numerator and denominator by n−1n - 1 turns these into sample covariances.

Step 3. β^=0.6/0.3=2\hat\beta = 0.6/0.3 = 2.

Answer: 2, the Wald ratio from Day 12. With several instruments and regressors, β^=(Z⊤X)−1Z⊤y\hat\beta = (Z^{\top}X)^{-1}Z^{\top}y, and a weak first stage (Z⊤XZ^{\top}X near singular) is an ill-conditioned system like Exercise 13.

Verify in Python

import numpy as np

A = np.array([[3, 1], [2, 4.]])
print("det =", round(np.linalg.det(A), 6), "\ninverse =\n", np.linalg.inv(A))
print("solution:", np.linalg.solve(A, [9, 16]))
print("3x3 det:", round(np.linalg.det(np.array([[2, 0, 1], [1, 3, 2], [1, 1, 1.]])), 10))

M = np.array([[1, 2], [1, -3.]])
print("equilibrium (Q, P):", np.linalg.solve(M, [120, 20]), " d/dY:", np.linalg.solve(M, [0.5, 0]))

B = np.array([[1, 1], [1, 1.001]])
print("ill-conditioned:", np.linalg.solve(B, [2, 2.001]), np.linalg.solve(B, [2, 2.002]),
      " condition number:", round(np.linalg.cond(B)))

L = np.array([[0.2, 0.3], [0.4, 0.1]])
print("Leontief output:", np.linalg.solve(np.eye(2) - L, [100, 50]).round(2))

Key takeaways

  • Ax=bAx = b has a unique solution iff det⁡A≠0\det A \ne 0, iff AA has full rank.
  • ∣det⁡A∣|\det A| is an area/volume scale factor; a determinant near zero means a nearly flat (fragile) map.
  • Equilibrium models, input–output models and IV estimators are all linear systems.

Simulation Lab: Solving Ax = b

Open full screen →

Two equations as two lines: as the determinant shrinks, the solution becomes fragile and then disappears.

x + y = 2.00
x + 1.50·y = 2.50
det A = c − 1
0.500
solution (x, y)
(1.00, 1.00)
condition number
10.4
large = fragile

Each equation is a line; the solution is where they cross. As c → 1 the lines become parallel, det A → 0 and the crossing point races off: a tiny change in b moves the solution a lot. That is ill-conditioning.

Day 18Day 20