Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and...

49
Matrix Algebra and Applications Dudley Cooke Trinity College Dublin Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 1 / 49

Transcript of Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and...

Page 1: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

Matrix Algebra and Applications

Dudley Cooke

Trinity College Dublin

Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 1 / 49

Page 2: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

EC2040 Topic 2 - Matrices and Matrix Algebra

Reading

1 Chapters 4 and 5 of CW

2 Chapters 11, 12 and 13 of PR

Plan

1 Matrices and Matrix Algebra

2 Transpose, Inverse, and Determinant of a Matrix

3 Solutions to Systems of Linear Equations

Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 2 / 49

Page 3: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

Matrices and System of Equations

A matrix is an array of numbers. Some examples are,

A =[

2 37 2

], B =

2 35 −101 1

, C =

2514

Notation: We shall use a capital letter to denote a matrix and thecorresponding small letter to denote individual elements of a matrix.

The element in the (2, 1) position (2nd row, 1st column) of A will be

denoted as a21. So, from above, A =[

a11 a12

a21 a22

].

The number of rows and columns in a matrix is also called its orderor dimension. For instance, the matrix A has order 2× 2.

Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 3 / 49

Page 4: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

Special Types of Matrices

Square matrix which has the same number of rows as columns (ordern× n)

Row matrix (order 1× n)

Column matrix (order n× 1).

A vector is a matrix having either a single row or a single column.

Two special types of square matrices are the null matrix (all entrieszero) and the identity matrix which has 1 along the diagonal andzeros everywhere else:

1 0 . . . 00 1 . . . 0...

......

...0 0 . . . 1

A square matrix where the only non-zero entries are on the diagonal isalso called a diagonal matrix.

Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 4 / 49

Page 5: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

Matrices in Economics

One example of a matrix in economics is the IS-LM macro model.1

Y = C + I + G (resource constraint)

C = a + b(1− t)Y (consumption function)

I = e − lR (investment function)

M = kY − hR (money demand)

We can write the above system in matrix notation as:1 −1 −1 0

−b(1− t) 1 0 00 0 1 lk 0 0 −h

YCIR

=

GaeM

Question: what happens to consumption when we increase the moneysupply (expansionary monetary policy).

1Recall, IS (the first three equations) and LM gives AD, where G and M are‘government policies’.

Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 5 / 49

Page 6: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

Arithmetical Operations on Matrices

Addition and Subtraction of matrices is very easy but can be doneonly when all the matrices have the same dimension.

Thus, Am×n + Bp×q is defined only when m = p and n = q.

Example:[4 31 2

]=A2×2

+[

1 25 6

]=B2×2

=[

4 + 1 3 + 21 + 5 2 + 6

]=[

5 58 6

]

That is, m = p = n = q = 2.

Clearly,

[a11 a12

a21 a22

]=A2×2

and

c11

c12

c13

=C3×1

cannot be added together.

Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 6 / 49

Page 7: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

Arithmetical Operations on Matrices

Formal Definition: Suppose that we have two matrices A = [aij ]m×n

and B = [bij ]m×n.

Then, the matrix A + B is simply [aij + bij ]m×n. E.g., for them = n = 2 case,[

a11 a12

a21 a22

]=A2×2

+[

b11 b12

b21 b22

]B2×2

=[

a11 + b11 a12 + b12

a21 + b21 a22 + b22

]

Similarly, the matrix A− B is simply [aij − bij ]m×n.

This process easily extends to the case when we have many matrices.For instance - if we have three matrices A, B, C of the samedimension - then A + B + C is the matrix formed by adding thecorresponding (i , j)th entries of A, B and C .

Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 7 / 49

Page 8: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

Scalar Multiplication

Scalar Multiplication by a number c is just multiplying each elementof the matrix by the number c .

For instance if A =

2 13 94 52 2

and c = 5/2 then c · A is the

matrix

5 5/2

15/2 45/210 25/25 5

.

Note that scalar multiplication applies to any matrix. We cancombine the operations of scalar multiplication and addition: forinstance, you should be able to say what 5A + 3B means if A and Bhave the same dimension.

Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 8 / 49

Page 9: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

Matrix Multiplication

Matrix Multiplication is somewhat more complicated (but all it reallyrequires is concentration).

Suppose that we have two matrices Am×n and Bp×q.

The product AB is defined only when n = p, that is when the numberof columns in A equals the number of rows in B.

1 This means that the product BA is defined only when q = m.

2 It is possible that AB is defined but BA is not defined.

3 Furthermore, even if AB and BA are both defined it is possible thatthey do not give the same matrix.

Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 9 / 49

Page 10: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

Matrix Multiplication

The bottom line is, the order of operation is important in matrixmultiplication.

Mathematically, we say that matrix multiplication is not commutative(whereas the scalar case is).

All this is very different from ordinary multiplication.

Take the previous example:

A2×2 =[

4 31 2

]and B2×2 =

[1 25 6

]What are AB and BA?

Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 10 / 49

Page 11: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

Matrix Multiplication for the 2 by 2 case

First, AB is,

AB =[

4 31 2

] [1 25 6

]=[

4 (1) + 3 (5) 4 (2) + 3 (6)1 (1) + 2 (5) 1 (2) + 2 (6)

]=[

19 1711 14

]However, BA is,

BA =[

1 25 6

] [4 31 2

]=[

1 (4) + 2 (1) 1 (3) + 2 (2)5 (4) + 6 (1) 5 (3) + 6 (2)

]=[

6 726 27

]So, AB is not BA.

Again, think about this versus the scalar case. If a = 5 and b = 6,ab = ba = 30.

Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 11 / 49

Page 12: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

Formal Definition of Matrix Multiplication

Suppose we have two matrices A = [aij ]m×n and B = [bij ]n×p.

The product AB is a m× p matrix [cij ]m×p where,

cij = ai1b1j + ai2b2j + . . . + ainbnj .

Loosely speaking, cij is the “product” of the ith row of A and the jthcolumn of B.

Again, for the 2 by 2 case, we have:

AB =[

a11 a12

a21 a22

] [b11 b12

b21 b22

]=[

a11 (b11) + a12 (b21) a11 (b11) + a12 (b21)a21 (b12) + a22 (b22) a21 (b12) + a22 (b22)

]=[

c11 c12

c21 c22

]≡ C

Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 12 / 49

Page 13: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

Example

Suppose A =

1 23 45 6

and B =[

7 89 10

]and AB = C , if

possible.

Since A has order 3× 2 and B has order 2× 2, it follows thatC = AB is defined and the product is a matrix of dimension 3× 2.

The individual elements of C (e.g., c11 = a11b11 + a12b21) are:c11 = (1× 7) + (2× 9) = 25, c12 = (1× 8) + (2× 10) = 28,c21 = (3× 7) + (4× 9) = 57, c22 = (3× 8) + (4× 10) = 64,c31 = (5× 7) + (6× 9) = 89, c32 = 5× 8 + 6× 10 = 100.

Hence, C =

c11 c12

c21 c22

c31 c32

=

25 2857 6489 100

.

Note that BA is not defined as elements a31 = 5 and a32 = 6 cannotbe matched with elements of B.

Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 13 / 49

Page 14: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

Null and Identity Matrix Multiplication

The null and identity matrix cases are trivial.

The identity matrix plays the role of 1 in the scalar case.

Scalar case:3× 1 = 3

Matrix case:[4 31 2

] [1 00 1

]=[

4 (1) + 3 (0) 4 (0) + 3 (1)1 (1) + 2 (0) 1 (0) + 2 (1)

]=[

4 31 2

]The null matrix plays the role of zero. As with 3× 0 = 0, so,[

4 31 2

] [0 00 0

]=[

4 (0) + 3 (0) 4 (0) + 3 (0)1 (0) + 2 (0) 1 (0) + 2 (0)

]=[

0 00 0

]

Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 14 / 49

Page 15: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

Recap: Rules for Scalars versus Matrices

Scalar cases:

1 Commutative; a + b = b + a

2 Associative; (a + b) + c = a + (b + c) and (ab) c = a (bc)3 Distributive; a (b + c) = ab + ac and (b + c) a = ba + ca

Matrix cases:

1 Addition

Commutative law; A + B = B + AAssociative law; (A + B) + C = A + (B + C )

2 Multiplication

Associative law; (AB) C = A (BC )Distributive law; A (B + C ) = AB + AC and (B + C ) A = BA + CA

Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 15 / 49

Page 16: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

Transpose of a Matrix

The transpose of a matrix A is formed by interchanging the rows andcolumns of A.

If A has order m× n, then it’s transpose has dimension n×m.

The transpose of A is generally denoted as AT and sometimes A′.

If A = AT , then we say that A is a symmetric matrix. A symmetric

matrix must be a square matrix (e.g., A = AT =[

1 33 1

]).

Transpose of a square matrix:

A =[

a11 a12

a21 a22

]⇒ AT =

[a11 a21

a12 a22

]

Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 16 / 49

Page 17: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

Properties of the Transpose

The transpose operation has the following properties.

1 (AT )T = A

2 (A + B)T = AT + BT . Suppose A =[

4 31 2

]⇒ AT =

[4 13 2

]and B =

[1 25 6

]⇒ BT =

[1 52 6

]. Try this at home.

3 (AB)T = BT AT

More generally, if we have n-matrices A1, A2, . . . , An then

(A1A2 . . . An)T = ATn AT

n−1 . . . AT2 AT

1

Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 17 / 49

Page 18: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

The Inverse of a Square Matrix

For a square matrix, An×n, the following is always true:

AIn = InA = A

If we can find a matrix Bn×n satisfying AB = BA = In, then we saythat B is the inverse matrix of A. The inverse matrix of A is denotedA−1.

Not all square matrices have inverses.

1 A matrix which has an inverse is called non-singular.

2 A matrix which does not have an inverse is called singular.

Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 18 / 49

Page 19: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

The Determinant of a Square Matrix

We denote the determinant of A, as |A|.The determinant of a 1× 1 matrix is trivial: it is the number itself.

The determinant of a 2× 2 matrix A =[

a11 a12

a21 a22

]is,

|A| = a11a22 − a12a21

The procedure for bigger matrices is more complicated. Let A be an× n matrix. Let Mij denote the determinant of the matrix derivedfrom A by deleting the ith row and jth column. Let Cij = (−1)i+jMij .

We refer to Mij as a minor and Cij as a co-factor.

Note: A square matrix A has an inverse if and only if its determinantis non-zero (is non-singular).

Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 19 / 49

Page 20: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

The Determinant of a Square matrix

Pick any row or column in the matrix. Suppose we pick the ith row.Then, the determinant of the matrix A is:

|A| = ai1Ci1 + ai2Ci2 + . . . + ainCin

If we pick the a column, say the jth one, then the determinant iscomputed as:

|A| = a1jC1j + a2jC2j + . . . + anjCnj

Observe that we could have picked any row or column: we will alwaysget the same answer. For practical considerations, we try to pick outa row or column which has the maximum number of zeros.

Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 20 / 49

Page 21: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

The Determinant of a Square matrix, 2 by 2 case

Suppose we have the following matrix: A =[

1 23 4

]. We know

|A| = (1× 4)− (2× 3) = −2.

Although it’s a little trivial, we can relate that to the technique forlarger matrices, as a first step.

We have,

|A| = (a11 × C11) + (a12 × C12)

=[a11 × (−1)1+1M11

]+[a12 × (−1)1+2M12

]= a11M11 − a12M12; M11 = 4 and M12 = 3

= a114− a123 = (1× 4)− (2× 3) = −2

Why is this all so easy? In the 2 by 2 case, the Mij ’s are scalars. Ifwe have a 3 by 3 case, the Mij are 2 by 2 matrices, which we have towork out the determinant of first etc...

Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 21 / 49

Page 22: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

3 by 3 Example

Suppose we have the following 3 by 3 matrix, A =

1 2 34 2 67 8 9

.

Let us compute the determinant by computing the co-factors of thefirst row.

We have, Cij = (−1)i+jMij , so,

C11 = (−1)1+1M11 = (−1)1+1

∣∣∣∣ 2 68 9

∣∣∣∣︸ ︷︷ ︸M11

But we know that M11 = (8× 6)− (2× 9) = 48− 18 = 30.

We conclude that C11 = −30.

Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 22 / 49

Page 23: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

3 by 3 Example Continued

We can do this for the other 2 elements of the row. We find,

C12 = (−1)1+2

∣∣∣∣ 4 67 9

∣∣∣∣︸ ︷︷ ︸=M12

= 6

C13 = (−1)1+3

∣∣∣∣ 4 27 8

∣∣∣∣ = 18

Hence, the determinant, call it ∆ for short, is,

∆ = a11C11 + a12C12 + a13C13 = a11M11 − a21M21 + a13M13

= [1× (−30)] + (2× 6) + (3× 18) = 36

We could have chosen any other row or column. If we choose thethird column, then we have: C13 = 18, C23 = 6, C33 = −6 andtherefore ∆ = (3× 18) + (6× 6) + [9× (−6)] = 36.

Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 23 / 49

Page 24: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

Properties of the Determinant

There are some useful properties of determinants (that we won’tprove) which can simplify the computation of the determinantsignificantly.

1 If a row or column of A is multiplied by c , then the determinant ofthe new matrix is c |A|.

2 Multiplying a row (column) by a non-zero constant and adding it toanother row (column) has no effect on the determinant.

Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 24 / 49

Page 25: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

Extended Example with Common Factors

Common factors basically involves ‘taking things outside the brackets’,as we usually do, except we can use the properties of the determinant.

Consider the same matrix as before, A =

1 2 34 2 67 8 9

.

Note that the second row can be written as2[

2 1 3]

=[

4 2 6].

We know that multiplying a row by a constant leads the determinantto change by the same factor.

It follows,

|A| = 2

∣∣∣∣∣∣1 2 32 1 37 8 9

∣∣∣∣∣∣Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 25 / 49

Page 26: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

Example Continued

Note that column three also has a common factor of 3, i.e.,

3

113

=

339

.

It follows that,

|A| = (2× 3)

∣∣∣∣∣∣1 2 12 1 17 8 3

∣∣∣∣∣∣ = 6

∣∣∣∣∣∣1 2 12 1 17 8 3

∣∣∣∣∣∣There are now no common factors; however we can now make use ofthe row and column operations.

Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 26 / 49

Page 27: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

Example Continued

Since the determinant is not changed by multiplying a row (column)by a constant and adding it to another row (column) we can use thisto make some entries in a row or column zeros.

Multiplying the first row by −1 and adding it to the second gives,

|A| = 6

∣∣∣∣∣∣1 2 11 −1 07 8 3

∣∣∣∣∣∣What did we do? Well, we started with 6

∣∣∣∣∣∣1 2 12 1 17 8 3

∣∣∣∣∣∣ and we noted,

(−1)

121

T

+

211

T

=

1−10

T

, which is the new middle row

of |A|.Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 27 / 49

Page 28: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

Example Continued

Similarly, multiplying the first row by −3 and adding it to the thirdrow gives:

|A| = 6

∣∣∣∣∣∣1 2 11 −1 04 2 0

∣∣∣∣∣∣Following the same idea as before, we start out with

|A| = 6

∣∣∣∣∣∣1 2 11 −1 07 8 3

∣∣∣∣∣∣ and we note,

(−3)

121

T

+

783

T

=

420

T

, which is the new bottom row of

|A|.

Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 28 / 49

Page 29: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

Example Continued

Why did we do all of this? Well, |A| =

∣∣∣∣∣∣1 2 34 2 67 8 9

∣∣∣∣∣∣ is not that easy

to compute.

However, |A| = 6

∣∣∣∣∣∣1 2 11 −1 04 2 0

∣∣∣∣∣∣ is easy to compute, as we can take

the cofactors of the third column.

In that case, we only have to compute one cofactor since two entriesin the column are zero.

Therefore, we have,

|A| = 6×[

1× (−1)1+3

∣∣∣∣ 1 −14 2

∣∣∣∣] = 6× 6 = 36

Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 29 / 49

Page 30: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

Computing the inverse using the determinant

We observed before that we can find the inverse of a square matrix Aif and only if |A| 6= 0.

When the determinant exists, it can be shown that the inverse isgiven by,

A−1 =1

|A| [cij ]T

where [cij ] is the matrix of cofactors of A.

In words, what we do is the following:

1 Replace each element of A by its cofactor.

2 Take the transpose of the matrix.

3 Scalar multiply this matrix by 1/|A|.

Note: the following is also used, adj (A) ≡ [cij ]T ; it is called theadjunct.

Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 30 / 49

Page 31: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

A 2 by 2 Example of Matrix Inversion

Consider the following 2 by 2 matrix A =[

3 21 0

].

We know that |A| = (3× 0)− (1× 2) = −2. Since |A| 6= 0, aninverse must exist.

The cofactor matrix (notice how easy it is in this case, again due to

zeros) is the following; cij =[

0 −1−2 3

]⇒ [cij ]T =

[0 −2−1 3

]Then, A−1 = 1

|A| [cij ]T = − 12

[0 −2−1 3

]= − 1

2

[0 112 − 3

2

].

Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 31 / 49

Page 32: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

The Inverse of a Square Matrix

Consider the following 2 by 2 matrix: A =[

1 λ3 4

]. Does this

matrix have an inverse?

We know an inverse only exists if the matrix is non-singular. For thisto hold, we require, |A| 6= 0.

We know that if |A| = (1× 4)− (3× λ) = 0 the matrix is singular.That is, we can’t find the inverse of A if λ = 4/3.

Finding a singularity tends to become a problem is we have very bigmatrices (say we have a big model) which is relatively sparse (that is,has lots of zeros in it).

Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 32 / 49

Page 33: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

3 by 3 Example

Let us compute the inverse of the matrix that we have seen before:

A =

1 2 34 2 67 8 9

.

We already know the following:

C11 = −30, C12 = 6, C13 = 18, C23 = 6, C33 = −6

⇒ |A| = 36

Recall we can use C1j ’s or Ci3’s to get here.

The remaining cofactors are C21 = 6, C22 = −12, C31 = 6, C32 = 6.Try this at home.

Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 33 / 49

Page 34: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

Matrix Inversion Example Continued

Here the matrix of cofactors is, [cij ] =

−30 6 186 −12 66 6 −6

.

The transpose is, [cij ]T =

−30 6 66 −12 6

18 6 −6

.

The inverse matrix is, A−1 = 1|A| [cij ]T =

− 56

16

16

16 − 1

316

12

16 − 1

6

as

|A| = 36.

Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 34 / 49

Page 35: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

Cramer’s Rule

Now suppose we have a ‘big linear model’.

In it’s most general specification it is written as a system of linearequations:

a11x1+ a12x2+ . . . + a1nxn = b1...

......

... =...

an1x1+ an2x2+ . . . + annxn = bn

This is system of n linear equations in n unknowns. It can berepresented compactly in matrix notation as Ax = b where,

A =

a11 . . . a1n...

......

an1 . . . ann

, x =

x1...

xn

, b =

b1...

bn

.

Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 35 / 49

Page 36: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

Cramer’s Rule

We note that providing |A| 6= 0 (that is, A has an inverse) we cansolve for x by just multiplying both sides of the equation Ax = b byA−1:

(A−1)Ax = (A−1A)x = Inx = x = A−1b

Cramer’s rule is just an alternative formula for this; the advantage ofthe rule is that we can find each xi individually; this may be useful ifwe don’t want to find the value of all xi .

Cramer’s Rule states that:

xi =|Ab,i ||A|

Here Ab,i is the matrix where the ith column of A is replaced by thecolumn vector b.

Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 36 / 49

Page 37: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

Examples of solving for a specific variable

Consider the system

2 3 74 4 41 5 1

A

wyz

x

=

621

b

. Here, |A| = 80;

hence the system is solvable.

We can compute w independently of y and z as,

w =

∣∣∣∣∣∣6 3 72 4 41 5 1

∣∣∣∣∣∣|A| = −48

80= −3

5

Computation of y and z is left as an exercise.

Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 37 / 49

Page 38: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

Why does Cramer’s Rule work?

Cramer’s Rule is equivalent to finding the inverse of A. To see thismore formally, consider the system, a11 a12 a13

a21 a22 a33

a31 a32 a33

wyz

=

b1

b2

b3

.

Now note that the inverse of A can be written as,

A−1 =1

|A|

C11 C21 C31

C12 C22 C32

C13 C23 C33

where Cij is the co-factor of aij .

Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 38 / 49

Page 39: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

Why does Cramer’s Rule work?

Hence, we have, wyz

= A−1b =1

|A|

b1C11 + b2C21 + b3C31

b1C12 + b2C22 + b3C32

b1C13 + b2C23 + b3C33

Now note that b1C11 + b2C21 + b3C31 is nothing but the determinantof the matrix where the first column of A has been replaced by thevector b.

Similarly, b1C12 + b2C22 + b3C32 is the determinant of the matrixwhere the second column of A has been replaced by the vector b.

You can check that a similar observation holds forb1C13 + b2C23 + b3C33. This shows that the inverse approach andCramer’s rule are identical for a system of three linear equations butthis approach can be easily extended.

Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 39 / 49

Page 40: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

A Demand and Supply Example

Consider a linear model of demand and supply (of ice-creams).

1 Demand for ice-creams depends on the price of ice-creams, theincome of individuals and the temperature.

2 The supply of ice-creams also depends on how much the ice-creamcompany can charge for it’s product and how hot it is.

qd = γM − bp + αT

qs = δp − εT + d

If income goes up, demand goes up. If the temperature goes up,demand goes up but supply goes down (some of the ice-cream meltsbefore it is sold). If price goes up, demand falls and supply rises. Inequilibrium, qd = qs .

Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 40 / 49

Page 41: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

A Demand and Supply Example

It is very easy to solve this model. The solution for the price is,

p∗ = γM+(α+ε)T−dδ+b . Higher temperatures result in higher prices as

people eat more ice-creams and ice-creams melt, reducing supply.

We can also draw the model in (p, q) space and ‘shift the curves’.More importantly, we can also represent the model in matrix form.[

b 1−δ 1

]A

[pq

]=[

γM + αTd − εT

]

Now we need |A| = b + δ 6= 0. If we look at p∗, that makes a lot ofeconomic sense. We can’t have an infinite price for ice-cream.

Again, we can also use Cramer’s rule to solve for shocks to income ortemperature.

Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 41 / 49

Page 42: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

Demand and Supply

The supply and demand example is trivial. However, we mightimagine that the entire economy (not just one market) consists of‘many’ demand and supply schedules (what we called a big linearmodel).

The demand and supply schedules will probably display some form ofinterdependence. That is, consider an economy with ice-creams andapples. If the temperature goes up, the demand for apples mightdrop. Why? Because, with given income, the demand for ice-creamrises.

If this is the case, our economy consists of an entire vector of pricesand a vector of quantities. We want to know the price and quantitiesin equilibrium.

That turns out to be very complicated. Having a grasp of matrixalgebra is then very useful as we want to know if an equilibrium exists.

Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 42 / 49

Page 43: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

Returning to the example at the very beginning

Consider the macroeconomic model we wrote down at the beginning.

C = a + b(1− t)Y

I = e − lr

G = G

L = kY − hR

M = M

We want to solve this model to determine the endogenous variables(Y , C , I , R) in terms of the exogenous variables(G , a, b, t, e, k , h, l , M).

We can use all the new tools we have developed to solve the model.We’ll focus on solving for consumption as a function of monetary andfiscal policy.

Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 43 / 49

Page 44: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

Macro Model Example

The equilibrium in this system is determined by the conditions:

Y = C + I + G

C = a + b(1− t)Y

I = e − lR

M = kY − hR

We can write the above system in matrix notation as:1 −1 −1 0

−b(1− t) 1 0 00 0 1 lk 0 0 −h

YCIR

=

GaeM

The first thing to do is to compute |A| which is needed no matterwhich approach we use to solve this system. We choose one of therows or columns with the maximum number of zeros since that willsimplify the computation.

Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 44 / 49

Page 45: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

Example Continued

Suppose we choose row 2. We know, ∆ = ∑4j=1 a2jC2j .

Then, ∆ = −b(1− t)︸ ︷︷ ︸=a21

C21 + C22, as a22 = 1 and a23 = a24 = 0.

Also Cij = (−1)i+jMij so ∆ = ∑4j=1 a2j (−1)2+jM2j . However, it is

not as easy as before because the M2j ’s are 3 by 3 matrices.

We only have two of them, in this case.

C21 = (−1)2+1

∣∣∣∣∣∣−1 −1 00 1 l0 0 −h

∣∣∣∣∣∣ C22 = (−1)2+2

∣∣∣∣∣∣1 −1 00 1 lk 0 −h

∣∣∣∣∣∣

Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 45 / 49

Page 46: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

Example Continued

Expanding the 3× 3 determinant in the expression for C21 about thefirst column (two zero elements), we get,

C21 = − [(−1)(1× (−h)− 0× l)] = −h

For C22 we can expand the 3× 3 determinant about the first column(one zero element):

C22 = (−1)1+1 × 1×∣∣∣∣ 1 l

0 −h

∣∣∣∣+ (−1)3+1 × k ×∣∣∣∣ −1 0

1 l

∣∣∣∣= −h− kl

Hence the determinant of the original 4× 4 is,

∆ = bh(1− t)− h− kl = −h(1− b(1− t))− kl

Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 46 / 49

Page 47: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

Example Continued

We can now compute the value of any of the endogenous variablesusing Cramer’s Rule. Suppose we want to compute C . We replace

the second column with[

G a e M]T

. Then,

C =1

|A|

∣∣∣∣∣∣∣∣1 G −1 0

−b(1− t) a 0 00 e 1 lk M 0 −h

∣∣∣∣∣∣∣∣Computing the determinant of the 4× 4 matrix by expanding aroundthe second row, we have

∆ = −b(1− t)× (−1)2+1 ×

∣∣∣∣∣∣G −1 0e 1 lM 0 −h

∣∣∣∣∣∣+ a× (−1)2+2

×

∣∣∣∣∣∣1 −1 00 1 lk 0 −h

∣∣∣∣∣∣Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 47 / 49

Page 48: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

Example Continued

The second 3× 3 determinant above has already been found.

Expanding this about the first 3× 3 around the first row, we have,∣∣∣∣∣∣G −1 0e 1 lM 0 −h

∣∣∣∣∣∣ = G × (−1)2 [1× (−h)− 0× l ] + (−1)

× (−1)3 [e × (−h)− M × l ]

This is −(hG + he + Ml).

Hence, ∆ = b(1− t)×−(hG + he + Ml) + a×−(h + kl) =− [b(1− t)(hG + he + Ml) + a(h + kl)]. It follows that

C =b(1− t)(hG + he + Ml) + a(h + kl)

h(1− b(1− t)) + kl

This is all exogenous; and G , M are policy variables.

Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 48 / 49

Page 49: Matrix Algebra and ApplicationsEC2040 Topic 2 - Matrices and Matrix Algebra Reading 1 Chapters 4 and 5 of CW 2 Chapters 11, 12 and 13 of PR Plan 1 Matrices and Matrix Algebra 2 Transpose,

Roundup

You should now be able to do the following:

1 Add/subtract/multiply matrices.

2 Find the inverse of a matrix and it’s determinant (which is basicallymatrix manipulation).

3 Apply these techniques to standard models and use Cramer’s rule tosolve for endogenous variables as functions of exogenous variables.

Dudley Cooke (Trinity College Dublin) Matrix Algebra and Applications 49 / 49