Lecture 2. Matrices
Lecture 2. Matrices
I
E
N
ADVANCED G
MATHEMATICS FOR
IE 7
0
LECTURE 2
0
MATRICES 2
A matrix is a collection of numbers (called elements) ordered by m rows and n
columns. It is usual to enclose the elements of a matrix in parentheses, brackets, or
braces. For example, the following is a matrix:
−4 1 3
𝐀=[ ]
−1 2 5
This matrix, matrix A, has two rows and three columns so it is referred to as a “2 x
3” matrix. The elements of a matrix are numbered in the following way:
A A12 A13
A = [ 11 ]
A21 A22 A23
Remember that the first subscript in a matrix refers to the row and the second
subscript refers to the column (Aij where i = row number and j = column number).
A vector is a special type of matrix that has only one row (called a row vector) or
one column (called a column vector). Below, a is a column vector while b is a row
vector.
7
𝐚 = [2]
3
𝐛 = [−2 7 4]
𝑠=[8]
Note: It is customary to denote scalars by italicized, lower case letters (e.g., s), to
denote vectors by bold, lower case letters (e.g., a, b), and to denote matrices with
more than one row and one column by bold, upper case letters (e.g., X).
0 0
𝐙=[ ]
0 0
1 6
𝐂=[ ]
3 2
1 9
𝐃 = [0 3 ]
7 −2
1
MATRICES 2
A symmetric matrix is a square matrix in which Xij = Xji for all i and j. Matrix F is
symmetric while G is not symmetric.
9 1 5
𝐅 = [1 6 2]
5 2 7
9 1 5
𝐆 = [2 6 2]
5 1 7
A diagonal matrix is a symmetric matrix where all the off diagonal elements are
zero (0). Matrix H is a diagonal matrix.
9 0 0
𝐇 = [0 6 0]
0 0 7
An identity matrix is a diagonal matrix with 1s and only 1s on the diagonal. The
identity matrix is almost always denoted as I.
1 0 0
𝐈 = [0 1 0]
0 0 1
Two matrices are considered to be equal if they are of the same order, and if all
their corresponding elements are equal.
1 4
1 2 3
𝐉=[ ] and 𝐉′ = [2 5]
4 5 6
3 6
The transpose of a row vector will be a column vector, and the transpose of a
column vector will be a row vector. The transpose of a symmetric matrix is simply the
original matrix.
In matrix algebra, the inverse of a matrix is that matrix which, when multiplied by
the original matrix, gives an identity matrix. The inverse of a matrix is denoted by the
superscript “-1”. Hence,
𝐀∗𝐀−𝟏 = 𝐀−𝟏 ∗ 𝐀 = 𝐈
A matrix must be square to have an inverse, but not all square matrices have an
inverse. In some cases, the inverse does not exist.
2
MATRICES 2
It is only possible to add two matrices if they are of the same order (same number
of rows and columns). If we add matrices J and K to give a result L, then each element
of L is simply the sum of the two corresponding elements of J and K.
If
1 2 3
𝐉=[ ]
4 5 6
0 −1 0
𝐊=[ ]
1 0 1
And
𝐉+𝐊=𝐋
Then,
1 2 3 0 −1 0 1 1 3
[ ]+[ ]=[ ]
4 5 6 1 0 1 5 5 7
1 1 3
𝐋=[ ]
5 5 7
𝐀+ 𝐁 = 𝐁 + 𝐀
(𝐀 + 𝐁) + 𝐂 = 𝐀 + (𝐁 + 𝐂)
Subtraction of two matrices is analogous with addition. For example using the
same J and K matrices to get the difference matrix M,
If
1 2 3
𝐉=[ ]
4 5 6
0 −1 0
𝐊=[ ]
1 0 1
And
𝐉−𝐊=𝐌
Then,
1 2 3 0 −1 0 1 3 3
[ ]−[ ]=[ ]
4 5 6 1 0 1 3 5 5
3
MATRICES 2
1 3 3
𝐌=[ ]
3 5 5
Matrix Multiplication
There are several rules for matrix multiplication. The first concerns the
multiplication between a matrix and a scalar. Scalar multiplication, i.e. multiplying a
matrix by a number is simply a matter of multiplying each element of the matrix by the
number.
1 2 3
For example: Find 3J, where 𝐉 = [ ]
4 5 6
1 2 3 3 6 9
𝟑𝐉 = 3 ∗ [ ]=[ ]
4 5 6 12 15 18
𝟑 ∗ 𝐀 = 𝐀 ∗ 𝟑
𝟑 ∗ (𝐀 + 𝐁) = 𝟑 ∗ 𝐀 + 𝟑 ∗ 𝐁
The next rule involves the multiplication of a row vector by a column vector. To
perform this, the row vector must have as many columns as the column vector has
rows.
RULE: Number of columns of the first matrix SHOULD BE EQUAL to the number of rows of
the second matrix.
For example,
2
[1 7 5] [4]
1
is legal since the number of columns of the row vector (3) is equal to the number of
rows of the column vector (3). However,
2
[1 7 5] [4]
1
6
is not legal because the row vector (first matrix) has three columns, while the column
vector (second matrix) has four rows.
4
MATRICES 2
The product of a row vector multiplied by a column vector will be a scalar. This
scalar is simply the sum of the first row vector element multiplied by the first column
vector element, plus the second row vector element multiplied by the second column
vector element, plus the product of the third elements, etc. Thus,
All other types of matrix multiplication involve the multiplication of a row vector
and a column vector.
Example:
1 7
2 8 −1
Find 𝐑 = 𝐍 ∗ 𝐏 where 𝐍 = [ ] and 𝐏 = [9 −2]
3 6 4
6 3
This is possible since matrix 𝐍 has three columns which is equal to the number of
rows of matrix 𝐏.
The resulting matrix, 𝐑, will have as many rows as the first matrix and as many
columns as the second matrix. Because N has two rows and P has two columns, R will
have two rows and two columns. We can multiply a 2 x 3 matrix and a 3 x 2 matrix,
resulting in a 2 x 2 matrix.
R R12
𝐑 = [ 11 ]
R 21 R 22
1
R11 = [2 8 −1] [9] = (2 ∗ 1) + (8 ∗ 9) + (−1 ∗ 6) = 68
6
7
R12 = [2 8 −1] [−2] = (2 ∗ 7) + (8 ∗ −2) + (−1 ∗ 3) = −5
3
1
R 21 = [3 6 4] [9] = (3 ∗ 1) + (6 ∗ 9) + (4 ∗ 6) = 81
6
7
R 22 = [3 6 4] [−2] = (3 ∗ 7) + (6 ∗ −2) + (4 ∗ 3) = 21
3
Hence,
1 7
2 8 −1 68 −5
𝐑=𝐍∗𝐏 [ ] [9 −2] = [ ]
3 6 4 81 21
6 3
5
MATRICES 2
Notice what happens if we change the order of these two matrices 𝐍 and 𝐏. This
time we are multiplying a 3 x 2 matrix with a 2 x 3 matrix, resulting to a 3 x 3 matrix which
is quite different from the previous result.
1 7
2 8 −1
Find 𝐑 = 𝐏 ∗ 𝐍 where 𝐏 = [9 −2] and 𝐍 = [ ]
3 6 4
6 3
2
R11 = [1 7] [ ] = (1 ∗ 2) + (7 ∗ 3) = 23
3
8
R12 = [1 7] [ ] = (1 ∗ 8) + (7 ∗ 6) = 50
6
−1
R 13 = [1 7] [ ] = (1 ∗ −1) + (7 ∗ 4) = 27
4
2
R 21 = [9 −2] [ ] = (9 ∗ 2) + (−2 ∗ 3) = 12
3
8
R 22 = [9 −2] [ ] = (9 ∗ 8) + (−2 ∗ 6) = 60
6
−1
R 23 = [9 −2] [ ] = (9 ∗ −1) + (−2 ∗ 4) = −17
4
2
R 31 = [6 3] [ ] = (6 ∗ 2) + (3 ∗ 3) = 21
3
8
R 32 = [6 3] [ ] = (6 ∗ 8) + (3 ∗ 6) = 66
6
−1
R 33 = [6 3] [ ] = (6 ∗ −1) + (3 ∗ 4) = 6
4
23 50 27
𝐑 = [12 60 −17]
21 66 6
−3
[ 4 ] [8 2]
7
6
MATRICES 2
In this case, the matrix multiplication is legal since the first matrix has one column
and the second matrix has one row. The resulting matrix will have as many rows as the
first matrix (3) and as many columns as the second matrix (2). Hence,
−3 −24 −6
[ 4 ] [8 2] = [ 32 8]
7 56 14
−3
[8 2] [ 4 ]
7
The operation will be illegal since the number of columns in the first matrix
(2) does not match the number of rows in the second matrix (3).
Inverse of a Matrix
[ 𝐀 | 𝐈 ] → [𝐈|𝐀−𝟏 ]
2 4 1
𝐕 = [−1 1 −1]
1 4 0
2 4 1 1 0 0
[ 𝐕 | 𝐈 ] → [−1 1 −1 |0 1 0]
1 4 0 0 0 1
Elements on positions V11, V22 and V33 shall be converted to 1, and all other values
to zero (0), thru elementary row operations. Solutions are done column by column
through matrix iterations.
7
MATRICES 2
Iteration 1:
Element V11 (2) needs to have a value of (1). Note that any action that will
be applied on an element will also be applied to all the elements within its row.
Also, operations that are only allowed are addition and/or multiplication and/or
division (no subtraction of element values).
1
2 4 1 1 0 0 ← 2 𝑅1
[ 𝐕 | 𝐈 ] → [−1 1 −1 |0 1 0]
1 4 0 0 0 1
1 1
1 0 0 2
[𝐕|𝐈]→[ 2 |2 ]
−1 1 −1 0 1 0
1 4 0 0 0 1
Now, elements V21 (-1) and V31 (1) should obtain values of zero (0). Multiplying
those values with zero is not advisable since all other elements within their rows
will also become zero. Note that the goal is to transform elements V11, V22 and
V33 to 1.
To do this, values must be multiplied to the new V11 (1) to be added to the
value on V22 (and later on V33), that will eventually turn the original values to zero.
1 1
1 2 0 0
2 2
[ 𝐕 | 𝐈 ] → [−1 1 −1 |0 1 0] ← 𝑅1 + 𝑅2
1 4 0 0 0 1 ← −𝑅1 + 𝑅3
1 1
1 2 0 0
2 2
1| 1
[𝐕|𝐈]→ 0 3 −2| 1 0
2
1 1
[0 2 −
2
−
2
0 1]
Iteration 2:
Values in the first column were transformed as required. Next, transform V22
(3) to (1) and other elements in the second column to zero.
1 1
1 2 0 0
2 2
1| 1 1
[𝐕|𝐈]→ 0 3 − | 1 0 ← 𝑅2
2 2 3
1 1
[0 2 −2 −2 0 1]
← −2𝑅2 + 𝑅1
8
MATRICES 2
1 1
1 2 0 0
2 2
1 1 1
[𝐕|𝐈]→ 0 1 − 6 || 0
6 3
1 1
[0 2 − − 0 1] ← −2𝑅2 + 𝑅3
2 2
The resulting matrix after working out with the second column is:
5 1 2
1 0 − 0
6 6 3
1 1 1
[ 𝐕 | 𝐈 ] → 0 1 − 6 || 0
6 3
1 5 2
[0 0 − 6 − 6 − 3 1]
Iteration 3:
5 1 2
1 0 −3 0
6 6
1 1 1
[ 𝐕 | 𝐈 ] → 0 1 − 6 || 0
6 3
1 ← −6𝑅3 5 2
[0 0 − 6 − 6 − 3 1]
5 1 2 5
1 0 −3 0 ← − 𝑅3 + 𝑅1
6 6 6
[ 𝐕 | 𝐈 ] → [0 1 − 1 |1 1
0 ] ← 𝑅3 + 𝑅2
1
6 6 3 6
0 0 1 5 4 −6
1 0 0 −4 −4 5
[ 𝐈 | 𝐕−𝟏 ] → [0 1 0 | 1 1 −1]
0 0 1 5 4 −6
−4 −4 5
𝐕 −𝟏 = [ 1 1 −1]
5 4 −6
2 4 1 −4 −4 5
𝐕 ∗ 𝐕 −𝟏 = [−1 1 −1] [ 1 1 −1] = 𝐈
1 4 0 5 4 −6
1 0 0
When multiplied, this should be equal to [0 1 0].
0 0 1