SigmaField
Mathematical Foundations for Quant Finance
0 of 256 lessons
      1. 3.3.1 Linear systems and Gaussian eliminationConcept · 30 min
      2. 3.3.2 Rank and the shape of the solution setConcept · 30 min
      3. 3.3.3 Practice set: linear systemsPractice set · 20 min
      4. 3.3.4 Case study: replicating a payoff, and complete marketsCase study · 35 min

Level 3, Linear algebra 3.3 Linear systems Lesson 2 of 4

ConceptLesson 3.3.2 in Level 3, Linear algebra. About 30 minutes.

Rank and the shape of the solution set

One, none or infinitely many

The system of lesson 3.3.1 had exactly one solution, the point where two lines cross. Lesson 1.2.1 found two other ways two lines can sit: parallel, or one line written twice.

Keep the first equation, x1+2x2=3x_1 + 2x_2 = 3, and change the second:

  • 2x1+x2=32x_1 + x_2 = 3: the lines cross once, at (1,1)(1, 1). One solution.
  • 2x1+4x2=52x_1 + 4x_2 = 5: halved, this is x1+2x2=2.5x_1 + 2x_2 = 2.5, a parallel line. No solution.
  • 2x1+4x2=62x_1 + 4x_2 = 6: halved, this is the first equation again. Every point of the line solves both. Infinitely many solutions.

One first equation, three second equations. Crossing lines share one point, parallel lines share none, and a line written twice shares all its points.

Rule: How many solutions

none, exactly one,or infinitely many\begin{gathered} \text{none, exactly one,} \\[2pt] \text{or infinitely many} \end{gathered}

A linear system never has exactly two solutions. If two different points solve it, so does every point on the line through them.

What elimination shows

Run elimination (lesson 3.3.1) on the three systems. In each, R2−2R1R_2 - 2R_1 clears the first column and leaves one new row.

second equationnew row 2readssolutions
2x1+x2=32x_1 + x_2 = 30, −3∣−30,\ -3 \mid -3−3x2=−3-3x_2 = -3one: (1,1)(1, 1)
2x1+4x2=52x_1 + 4x_2 = 50, 0∣−10,\ 0 \mid -10=−10 = -1none
2x1+4x2=62x_1 + 4x_2 = 60, 0∣00,\ 0 \mid 00=00 = 0infinitely many

A row 0=−10 = -1 is false whatever the unknowns are, so the system has no solution. A row 0=00 = 0 is true for every choice: it adds no condition, so only x1+2x2=3x_1 + 2x_2 = 3 is left.

In that last case x2x_2 can be anything. Call it tt; then x1=3−2tx_1 = 3 - 2t. Every value of tt gives a solution:

tt−1-1012
(x1,x2)(x_1, x_2)(5,−1)(5, -1)(3,0)(3, 0)(1,1)(1, 1)(−1,2)(-1, 2)

The column picture

Lesson 3.3.1 read Ax=bA\mathbf{x} = \mathbf{b} as a question: which combination of the columns gives b\mathbf{b}? Here the columns are a1=(1,2)\mathbf{a}_1 = (1, 2) and a2=(2,4)\mathbf{a}_2 = (2, 4). The second is twice the first, so both point along the same line through 0.

Every combination x1a1+x2a2x_1\mathbf{a}_1 + x_2\mathbf{a}_2 is a multiple of (1,2)(1, 2) and stays on that line. The point b=(3,6)\mathbf{b} = (3, 6) lies on it and is reached in many ways: 3a13\mathbf{a}_1, or a1+a2\mathbf{a}_1 + \mathbf{a}_2, or −a1+2a2-\mathbf{a}_1 + 2\mathbf{a}_2. The point (3,5)(3, 5) is off the line, and no combination reaches it.

Columns pointing in different directions reach every point of the plane. Columns along one line reach only that line: (3,6)(3, 6) on it, in many ways, and (3,5)(3, 5) off it, never.

Try it

Each loop pass builds one augmented matrix, does R2−2R1R_2 - 2R_1 and prints the new row 2.

The second loop checks the four solutions of the table in 2x1+4x2=62x_1 + 4x_2 = 6. The last line checks the three combinations that reach (3,6)(3, 6).

⌘/Ctrl + Enter runs the cell

Rank: the number of pivots

The rank of a matrix is the number of pivots in its row echelon form. It counts the equations that really constrain the unknowns, once repeats and combinations are cleared away.

  • (1221)\begin{pmatrix} 1 & 2 \\ 2 & 1 \end{pmatrix} has rank 2: elimination leaves pivots 1 and −3-3.
  • (1224)\begin{pmatrix} 1 & 2 \\ 2 & 4 \end{pmatrix} has rank 1: the second row becomes zeros.
  • The 3 × 3 matrix of lesson 3.3.1 has rank 3, with pivots 1, 1 and 3.

Rule: Rank

rank⁡A=number of pivots\operatorname{rank} A = \text{number of pivots}

Each pivot needs its own row and its own column. So the rank is at most the number of rows, and at most the number of columns. Count pivots after elimination, not nonzero rows before it.

A square n×nn \times n matrix of rank nn has a pivot in every column. Then Ax=bA\mathbf{x} = \mathbf{b} has exactly one solution for every b\mathbf{b}, and AA has an inverse (lesson 3.2.3).

With rank below nn, some column of AA is a combination of the others, as a2=2a1\mathbf{a}_2 = 2\mathbf{a}_1 above. Such a matrix has no inverse. Lesson 3.4.1 tests for this with the determinant, and lesson 3.5.1 calls the columns dependent.

Free variables and the shape of the solutions

In row echelon form, each column with a pivot gives a pivot variable. The unknowns of the other columns are free variables: they may take any value, and back substitution then fixes the pivot variables.

Rule: Free variables

free variables=n−rank⁡A\text{free variables} = n - \operatorname{rank} A

Here nn is the number of unknowns, the columns of AA. When the system has solutions, 0 free variables give a single point, 1 gives a line and 2 give a plane.

A line in space. Take three equations in three unknowns, with b=(4,9,13)\mathbf{b} = (4, 9, 13):

(1214243936413)\left(\begin{array}{ccc|c} 1 & 2 & 1 & 4 \\ 2 & 4 & 3 & 9 \\ 3 & 6 & 4 & 13 \end{array}\right)

The steps R2−2R1R_2 - 2R_1, R3−3R1R_3 - 3R_1 and then R3−R2R_3 - R_2 give

(121400110000)\left(\begin{array}{ccc|c} 1 & 2 & 1 & 4 \\ 0 & 0 & 1 & 1 \\ 0 & 0 & 0 & 0 \end{array}\right)

The pivots sit in columns 1 and 3, so the rank is 2 and x2x_2 is free.

Set x2=tx_2 = t. Row 2 gives x3=1x_3 = 1, and row 1 gives x1=4−2t−1=3−2tx_1 = 4 - 2t - 1 = 3 - 2t. The solutions form a line in R3\mathbb{R}^3, through (3,0,1)(3, 0, 1) in the direction (−2,1,0)(-2, 1, 0):

x=(301)+t(−210)\mathbf{x} = \begin{pmatrix} 3 \\ 0 \\ 1 \end{pmatrix} + t\begin{pmatrix} -2 \\ 1 \\ 0 \end{pmatrix}

A plane. In x1+x2+x3=1x_1 + x_2 + x_3 = 1, 2x1+2x2+2x3=22x_1 + 2x_2 + 2x_3 = 2, 3x1+3x2+3x3=33x_1 + 3x_2 + 3x_3 = 3, rows 2 and 3 are multiples of row 1. Elimination leaves one pivot, so the rank is 1 and two unknowns are free.

With x2=sx_2 = s and x3=tx_3 = t, every x1=1−s−tx_1 = 1 - s - t works. The solutions form a plane, which contains (1,0,0)(1, 0, 0), (0,1,0)(0, 1, 0), (0,0,1)(0, 0, 1) and (2,−1,0)(2, -1, 0).

Try it

np.linalg.matrix_rank returns the rank. The first line prints it for the four matrices above.

The loops put points of the line and of the plane back into each system. Every product reproduces the right-hand side.

⌘/Ctrl + Enter runs the cell

Is there a solution at all?

A system with at least one solution is consistent. Elimination on [A∣b][A \mid \mathbf{b}] settles it: the system has no solution exactly when some row reads 0=c0 = c with c≠0c \neq 0. That row has its pivot in the b\mathbf{b} column, so [A∣b][A \mid \mathbf{b}] has one more pivot than AA.

Change the last entry of b\mathbf{b} above from 13 to 12. The same steps now end in the row (0,0,0∣−1)(0, 0, 0 \mid -1), which reads 0=−10 = -1. The rank of AA is still 2, but the rank of [A∣b][A \mid \mathbf{b}] is 3.

Rule: Consistency

ranks differ: noneequal ranks=n: oneequal ranks<n:infinitely many\begin{gathered} \text{ranks differ: none} \\[4pt] \text{equal ranks} = n\text{: one} \\[4pt] \text{equal ranks} < n\text{:} \\ \text{infinitely many} \end{gathered}

The two ranks are those of AA and of [A∣b][A \mid \mathbf{b}]; the second can only be equal or larger by 1. Compare them first. If they are equal, the system is consistent, and the number of free variables, n−rank⁡An - \operatorname{rank} A, decides between one solution and infinitely many.

More equations than unknowns, or fewer

The rule works for systems of any shape. A tall system has more equations than unknowns. Take x1+x2=3x_1 + x_2 = 3, x1−x2=1x_1 - x_2 = 1 and x1+2x2=4x_1 + 2x_2 = 4: three lines in the plane.

Elimination with R2−R1R_2 - R_1, R3−R1R_3 - R_1 and R3+12R2R_3 + \frac{1}{2}R_2 leaves the row (0,0∣0)(0, 0 \mid 0). Both ranks are 2, the number of unknowns, so there is one solution, (2,1)(2, 1). Change the 4 to 5 and the last row is (0,0∣1)(0, 0 \mid 1): no solution.

Three lines rarely pass through one point, so a tall system usually has no solution. Its rank is at most the number of unknowns, below the number of equations, so some right-hand sides are always out of reach. Case study 3.3.4 meets this with three states of the world and two assets.

A wide system has fewer equations than unknowns. Take x1+x2+x3=6x_1 + x_2 + x_3 = 6 and x2−x3=1x_2 - x_3 = 1: the rank is 2 and there are 3 unknowns, so one is free.

With x3=tx_3 = t, the solutions are (5−2t, 1+t, t)(5 - 2t,\ 1 + t,\ t), a line. A wide system never has exactly one solution.

Try it

consistent compares the two ranks; np.column_stack puts b\mathbf{b} beside AA. The cell tests the 3 × 3 system with 13 and with 12, then the tall system with 4 and with 5.

The last line puts two points of the wide system's line back in: both give (6,1)(6, 1).

⌘/Ctrl + Enter runs the cell

Rank on a computer

On a computer, rounding hides zeros. In (0.10.70.32.1)\begin{pmatrix} 0.1 & 0.7 \\ 0.3 & 2.1 \end{pmatrix} the second row is 3 times the first, so the rank is 1. But 0.1, 0.3, 0.7 and 2.1 have no exact binary form, and elimination leaves 4.4×10−164.4 \times 10^{-16} where a 0 should be.

np.linalg.matrix_rank allows for this: it treats numbers that small, relative to the matrix, as zero, and returns 1. np.linalg.solve is less careful. Here it raises no error and returns numbers as large as 2×10162 \times 10^{16}, which mean nothing.

Try it

The cell does the elimination step by hand and prints what is left in the second pivot place. Then matrix_rank gives 1.

solve returns two huge numbers, printed to one digit. Check the rank before trusting solve on a matrix that may be singular.

⌘/Ctrl + Enter runs the cell

Nearly singular systems

A matrix can have full rank and still behave almost like a singular one. Take x1+x2=2x_1 + x_2 = 2 and x1+1.001x2=2.001x_1 + 1.001x_2 = 2.001, two lines that are almost parallel. The answer is (1,1)(1, 1).

Now move the right-hand side of the second equation a little:

b2b_22.0002.0012.0022.003
(x1,x2)(x_1, x_2)(2,0)(2, 0)(1,1)(1, 1)(0,2)(0, 2)(−1,3)(-1, 3)

A change of 0.001 in b2b_2 moves each unknown by 1. When two lines are nearly parallel, sliding one a little slides their meeting point a long way.

Such a system is ill-conditioned: small errors in the data, such as rounding or a mistyped price, become large errors in the answer. np.linalg.cond puts a number on it, the condition number, here about 4002. Case study 3.4.3 meets this with assets that are almost copies of each other.

Try it

The rank is 2, so there is one solution for each b2b_2, but it swings. np.round(…, 4) hides rounding in the last digits.

⌘/Ctrl + Enter runs the cell

The explorer shows the cases of this lesson in both pictures. Pick each preset in turn. On "Nearly parallel", move b2b_2 by one step of 0.05 and watch the meeting point jump by a whole unit.

Explore

Each row of the system is a line, and the solution is where the lines meet. The same numbers say how much of each column of A it takes to reach b. Change the entries and watch both pictures.

−6−6−3−33366

Rows: row 1 and row 2 as lines.

−6−6−3−33366a₁a₂b

Columns: x₁ copies of a₁, then x₂ of a₂, dashed.

System
(1221)x=(33)\begin{pmatrix} 1 & 2 \\ 2 & 1 \end{pmatrix}\mathbf{x} = \begin{pmatrix} 3 \\ 3 \end{pmatrix}
Solution
x₁ = 1, x₂ = 1
a₁₁a₂₂ − a₁₂a₂₁
−3
Sensitivity
if b₂ moves by 0.01, the solution moves by 0.0075
So
One solution: the lines cross at one point.

Common mistakes

  1. A row 0=00 = 0 is not a contradiction. It adds no condition; with fewer pivots than unknowns it means free variables.
  2. A row 0=c0 = c with c≠0c \neq 0 means no solution, not that some unknown is 0.
  3. Count pivots after elimination. (1224)\begin{pmatrix} 1 & 2 \\ 2 & 4 \end{pmatrix} has two nonzero rows but rank 1.
  4. Free variables are unknowns minus rank, n−rank⁡An - \operatorname{rank} A, where nn counts columns, not equations.
  5. Shape is not the whole story. A tall system can have exactly one solution, as (2,1)(2, 1) above. A wide one can never have exactly one.
  6. Do not trust a tiny pivot or a quiet solve. Check matrix_rank, and remember that a nearly singular system can magnify small errors.

Rank and solution sets

0 of 11 correct

  1. 1.
  2. 2.
  3. 3.
  4. 4.
  5. 5.
  6. 6.
  7. 7.
  8. 8.
  9. 9.
  10. 10.
  11. 11.
How to type answers
  • Powers with ^: x^7, 2^(1/3), a^-2.
  • Multiply with * or by writing side by side: 3x^2, 2(x+1).
  • ln(x) is the natural log, log(x, 2) is log base 2, e is Euler's number, sqrt(x) is a square root.
  • sin(x), cos(x) and tan(x) take radians; write pi for π and sin(x)^2 for sin²x.
  • Your first answer to each question is saved: it counts towards your score and brings the question back for review.
  • Exact answers like ln(20)/ln(3) are best. Decimals need about 4 significant figures.

Summary card

  • A linear system has no solution, exactly one, or infinitely many. In the plane: parallel lines, crossing lines, or one line written twice.
  • Elimination shows which: a row 0=c0 = c with c≠0c \neq 0 means none; a row 0=00 = 0 adds no condition.
  • The rank of AA is the number of pivots, at most the number of rows and of columns. A square n×nn \times n matrix has an inverse exactly when its rank is nn.
  • Free variables number n−rank⁡An - \operatorname{rank} A; the solutions form a point, a line or a plane for 0, 1 or 2 of them.
  • Consistent exactly when rank⁡[A∣b]=rank⁡A\operatorname{rank}[A \mid \mathbf{b}] = \operatorname{rank} A. Tall systems usually have no solution; wide ones never have exactly one.
  • np.linalg.matrix_rank allows for rounding; solve may not notice a singular matrix. A nearly singular system can turn small changes in b\mathbf{b} into large changes in x\mathbf{x}.

Free further reading

Optional. This lesson covers what you need; these add more examples and practice. All are free to read.