2 Matrix
2 Matrix
product
2 Matrix multiplication
Table of contents
1 Matrix Addition, Scalar Multiplication, and Transposition
Matrix addition
Scalar multiplication
Transpose of a Matrix
2 Matrix Multiplication
Matrix Multiplication
Application in Computer Graphics
3 Inverse Matrix
Inverse and Linear Systems
An Inversion Method
Application in Cryptography
4 Elementary Matrices
Elementary Matrices
Inverse and Elementary Matrices
5 Elimination equiv LU Factorization
Matrix
A rectangular array of numbers is called a matrix, denoted by uppercase
letters: A, B, C...
an m × n matrix or size m × n.
Simple notation A = [aij ]
(i, j) - entry : element lies in row i and column j, denoted by aij
Matrix Algebra 4 / 101
Matrix Addition, Scalar Multiplication, and Transposition
Row matrix
A matrix of size 1 × n is called a row matrix
h i
1 2 4 9
Column matrix
A matrix of size m × 1 is called a column matrix
" #
1
2
Square matrix
A m × m matrix is a square matrix
" #
1 2
4 9
Example
" #
1 2 −1
B=
0 5 6
is a 2 × 3 matrix.
The (2, 1) - entry is
b21 = 0
In the first row -1, 1, 0, 0 show that the first edge goes from node 1 to
node 2 ( -1 for node 1 because the arrow goes out, +1 for node 2 with
arrow in)
This graph is complete - every pair of nodes is connected by an edge.
Matrix Algebra 7 / 101
Matrix Addition, Scalar Multiplication, and Transposition
Equal matrices
A=B
if
1 They have the same size.
2 Corresponding entries are equal.
Example
Given
" # " # " #
a b 1 2 −1 1 0
A= ,B= and C =
c d 3 0 1 −2 2
Example
Given
" # " # " #
a b 1 2 −1 1 0
A= ,B= and C =
c d 3 0 1 −2 2
Matrix addition
If A and B are matrices of the same size, their sum A + B is the matrix
formed by adding corresponding entries.
If A = [aij ] and B = [bij ] then
A + B = [aij + bij ]
in other words
a11 a12 ··· a1n b11 b12 ··· b1n
a21
a22 ··· b21
a2n
b22 ··· b2n
+ .
. .. .. .. ..
. ..
..
. . . . .. . . .
an1 bm2 · · · amn bn1 bm2 · · · bmn
a11 + b11 a12 + b12 ··· a1n + b1n
a21 + b21
a22 + b22 ··· a2n + b2n
= .. .. .. ..
. . . .
an1 + bn1 bm2 + bm2 ··· amn + bmn
Example
If " # " #
2 1 3 1 1 −1
A= and B =
−1 2 0 2 0 6
then " # " #
2 + 1 1 + 1 3 + (−1) 3 2 2
A+B = =
−1 + 2 2 + 0 0+6 1 2 6
Example
Example
Solution
Add the matrices on the left side to obtain
h i h i
a + c b + a c + b = 3 2 −1
Zero matrix
The m × n matrix in which every entry is zero is called the m × n zero
matrix and is denoted as 0(or 0mn )
" #
0 0 0
023 =
0 0 0
Negative matrix
Negative of matrix A, denoted by −A obtained by multiplying each entry
of A by −1
−A = [−aij ]
Difference
If A and B are two m × n matrices, their difference A − B is defined by
A − B = A + (−B)
Example
Let
" # " # " #
3 −1 0 1 −1 1 1 0 −2
A= ,B = ,C =
1 2 −4 −2 0 6 3 1 1
Compute −A, A − B, A + B − C.
Example
Let
" # " # " #
3 −1 0 1 −1 1 1 0 −2
A= ,B = ,C =
1 2 −4 −2 0 6 3 1 1
Compute −A, A − B, A + B − C.
Solution
" #
−3 1 0
−A =
−1 −2 4
" # " #
3−1 −1 − (−1) 0 − 1 2 0 −1
A−B = =
1 − (−2) 2−0 −4 − 6 3 2 −10
" # " #
3 + 1 − 1 −1 − 1 − 0 0 + 1 − (−2) 3 −2 3
A+B−C = =
1−2−3 2+0−1 −4 + 6 − 1 −4 1 1
Example
Example
Scalar multiplication
kA = [kaij ]
Example
Solution
" # " #
15 −5 20 1 0.5 1 −0.5
5A = , B=
10 0 5 2 0 1.5 1
" # " # " #
9 −3 12 2 4 −2 7 −7 14
3A − 2B = − =
6 0 3 0 6 4 6 −6 −1
2 A + (B + C) = (A + B) + C (associative law)
3 0 + A = A for each A.
4 A + (−A) = 0
5 k(A + B) = kA + kB.
6 (k + p)A = kA + pA.
7 (kp)A = k(pA).
8 1A = A.
Example
Example
Transpose of a Matrix
aTij = aji
The first row of AT is the first column of A (that is it consists of the
entries of column 1 in order). Similarly the second row of AT is the second
column of A, and so on.
Example
Example
Solution
5 " # 3 1 −1
T
h
T
i
T 1 3 4 T
A = 1 3 2 , B = 2 , C = ,D = 1 3 2 = D
2 4 6
6 −1 2 1
Definition (Symmetric)
A matrix A is symmetric if AT = A
Example
1 2 3
A = 2 4 5 is a symmetric matrix
3 5 6
0 2 3
B = −2 0 −4 is a skew symmetric matrix
−3 4 0
Let A and B denote matrices of the same size, and let k denote a scalar.
1 If A is an m × n matrix, then AT is an n × m matrix.
2 (AT )T = A.
3 (kA)T = kAT .
4 (A + B)T = AT + B T .
Example
Solve for A if " #!T " #
T 1 2 2 3
2A − 3 =
−1 1 −1 2
Example
Solve for A if " #!T " #
T 1 2 2 3
2A − 3 =
−1 1 −1 2
Solution
Applying the above theorem for the left hand side, we have
" #T " #
1 2
T T 1 −1
LHS = 2(A ) − 3 = 2A − 3
−1 1 2 1
Table of contents
1 Matrix Addition, Scalar Multiplication, and Transposition
Matrix addition
Scalar multiplication
Transpose of a Matrix
2 Matrix Multiplication
Matrix Multiplication
Application in Computer Graphics
3 Inverse Matrix
Inverse and Linear Systems
An Inversion Method
Application in Cryptography
4 Elementary Matrices
Elementary Matrices
Inverse and Elementary Matrices
5 Elimination equiv LU Factorization
Vector in Rn
Example
" #
x1
: a vector in R2
x2
x1
x2 : a vector in R3
x3
Definition
Vector in Rn is a n × 1 matrix
x1
x
2
x=
. . .
xn
0
0
Vector zero 0 =
. . .
0
Two vectors are equal if and only if corresponding entries are the same
a1 b1
a b
2 2
= ⇐⇒ ai = bi ∀i
. . . . . .
an bn
x n + yn
Scalar multiplication
ax1
ax
ax = 2
...
axn
Matrix Algebra 33 / 101
Matrix Multiplication Matrix Multiplication
Example
2 3
−1 1
Let x = , y = then
1 2
2 −1
5 6 12
0 −3 −1
x+y= 3x = 3x + 2y =
3 3 7
1 6 4
is defined as
a • b = a1 b1 + a2 b2 + · · · + an bn
Example
is
a • b = (1)(2) + (2)(5) + (3)(−1) + (4)(0) = 9
Let
b1
h i b
a = a1 a2 . . . an and b = 2
. . .
bn
then the multiplication of a and b is given by
ab = aT • b = a1 b1 + a2 b2 + · · · + an bn
Matrix-vector product
Let A be an m × n matrix. If
h i
A = a1 . . . an
x1
..
x= .
xn
then
Ax = x1 a1 + · · · + xn an
Example
" # 2
2 −1 −3
Let A = and x = −3 then
4 2 −2
4
" # " # " # " #
2 −1 −3 −5
Ax = 2 −3 +4 =
4 2 −2 −6
can be written as
Ax ≡ x1 col1 (A) + x2 col2 (A) + · · · + xn coln (A) = b
The entries in the product Ax are merely the left sides of the equations in
the system. Hence the linear system can be written in matrix form as
Ax = b
can be written as
Ax ≡ x1 col1 (A) + x2 col2 (A) + · · · + xn coln (A) = b
The entries in the product Ax are merely the left sides of the equations in
the system. Hence the linear system can be written in matrix form as
Ax = b
Theorem
Ax = b has solution (is consistent) if and only if b can be expressed as a
linear combination of the columns of matrix A.
Matrix Algebra 44 / 101
Matrix Multiplication Matrix Multiplication
Example
Ax = b
−2 0 1 x 5
with A = 2 3 −4, x = y and b = 7
3 2 2 z 3
Example
Consider the linear system Ax = b where
3 1 2 4
4 −5 6 x1 1
A= , x = x2 , b =
0 7 −3 0
x3
−1 2 0 2
Exercise
Definition
Let Ah be an m × ni matrix and B be an n × k matrix. Write
B = b1 . . . bk where bj is column j of B then the product matrix
AB is the m × k matrix defined by
h i h i
AB = A b1 . . . bk = Ab1 . . . Abk
Example
2 3 5 8 9
Compute AB if A = 1 4 7 and B = 7 2
0 1 8 6 1
Example
2 3 5 8 9
Compute AB if A = 1 4 7 and B = 7 2
0 1 8 6 1
Solution
8 9
Columns of B are b1 = 7 and b2 = 2. So
6 1
2 3 5 8 67 2 3 5 9 29
Ab1 = 1 4 7 7 = 78 , Ab1 = 1 4 7 2 = 24
0 1 8 6 55 0 1 8 1 10
h i 67 29
Thus AB = Ab1 Ab2 = 78 24
55 10
Matrix Algebra 49 / 101
Matrix Multiplication Matrix Multiplication
C = AB
Compatible rule
Example
Example (cont)
Example (cont)
Practice Problem
An = A.A
| {z. . . A}
n times
and A0 = In
where
Identity matrix
The identity matrix In is the n × n matrix with 1s on the main diagonal
(upper left to lower right), and zeros elsewhere.
Properties
Example - zoom in
" #
2 0
If A = then the result of AD is
0 2
Slant an image
Figure
1: slant
the letter to the right by multiplying by an x-shear matrix
1 0.2
A=
0 1
0.8 0
Figure 2: shrink x -coordinate by 0.8 with t an x-scale matrix B =
0 1
◦
Figure 3: rotate the letter about
the origin through 30 by matrix
cos(π/6) − sin(π/6)
R π6 =
sin(π/6) cos(π/6)
Exercise
Table of contents
1 Matrix Addition, Scalar Multiplication, and Transposition
Matrix addition
Scalar multiplication
Transpose of a Matrix
2 Matrix Multiplication
Matrix Multiplication
Application in Computer Graphics
3 Inverse Matrix
Inverse and Linear Systems
An Inversion Method
Application in Cryptography
4 Elementary Matrices
Elementary Matrices
Inverse and Elementary Matrices
5 Elimination equiv LU Factorization
Inverse matrix
Example
" # " #
−1 1 0 1
Show that B = is an inverse of A = .
1 0 1 1
Example
" # " #
−1 1 0 1
Show that B = is an inverse of A = .
1 0 1 1
Solution
We have " #
1 0
AB = BA =
0 1
Hence B is an inverse of A
Example
Solution
Since A is a 2 × 2 matrix, A−1 is also a 2 × 2 matrix and satisfies
AA−1 = A−1 A = I2
AA−1 = I2 yields
" #" # " #
3 1 x y 1 0
=
5 2 z w 0 1
or ( (
3x + z = 1 5x + 2z = 0
and
3y + w = 0 5y + 2w = 1
" #
−1 2 −1
A =
−5 3
" #
−1 2 −1
A =
−5 3
Ax = b
A−1 Ax = A−1 b
Ix = A−1 b
x = A−1 b
Example
Solve the system equations
3x1 + x2 = 3
5x1 + 2x2 = 8
Solution
" # " #
3 1 x
Matrix form of the system is Ax = b where A = ,x= 1 ,
5 2 x2
" #
3
b= .
8
" #
2 −1
A has the inverse A−1 = . So the solution of the system is
−5 3
" #" # " #
−1 2 −1 3 −2
x=A b= = or x1 = −2, x2 = 9
−5 3 8 9
Matrix Algebra 70 / 101
Inverse Matrix An Inversion Method
Example
Find inverse of
Solution
Step 1
Solution
Step 1
Step 2
Solution
Step 1
Step 2
Step 3
" #
6 −2
A−1 =
−2 1
Matrix Algebra 73 / 101
Inverse Matrix An Inversion Method
Practice
(reverse order).
4 Ak is invertible for any k ≥ 1, and (Ak )−1 = (A−1 )k .
operations.
4 The system Ax = b has at least one solution x for every choice of
column b.
5 There exists an n × n matrix C such that AC = I .
n
Crypography
Example
Cryption
Encrypt a message of 4 letters such as STOP as following
Represent message |{z}
S |{z}
T |{z}
O |{z}
P by matrix
19 20 15 16
" #
19 20
D=
15 16
" #
1 −3
We use an encoding matrix M = to encrypt the message
−1 4
by transformation
" #" # " #
1 −3 19 20 −26 −28
MD = =
−1 4 15 16 41 44
Encryption
You receive an encoded massege NCAA. Need to encrypt to find the origin
message.
Encryption
You receive an encoded massege NCAA. Need to encrypt to find the origin
message.
The principal is as following: If we denote D and E be the matrix
representation for origin message and encoded message then
E = MD
D = M −1 E
mod p)
4 To decode, multiply each block by the inverse matrix D( mod p).
Table of contents
1 Matrix Addition, Scalar Multiplication, and Transposition
Matrix addition
Scalar multiplication
Transpose of a Matrix
2 Matrix Multiplication
Matrix Multiplication
Application in Computer Graphics
3 Inverse Matrix
Inverse and Linear Systems
An Inversion Method
Application in Cryptography
4 Elementary Matrices
Elementary Matrices
Inverse and Elementary Matrices
5 Elimination equiv LU Factorization
Elementary Matrices
Example
" #
0 1
E1 = : interchanging rows 1 and 2: elementary of type I
1 0
" #
1 0
E2 = : multiplying row 2 by 9: elementary of type II
0 9
" #
1 5
E2 = : adding 5 times row 2 to row 1: elementary of type III
0 1
" #
a b c
More concretely, consider A = then
p q r
" #" # " #
0 1 a b c p q r
E1 A = =
1 0 p q r a b c
Example
0 1 0
E1 = 1 0 0
0 0 1
corresponds to exchanging rows 1 and 2 (type I). So the inverse
0 1 0
E1−1 = 1 0 0
0 0 1
Example
1 0 0
E2 = 0 1 0
0 0 9
corresponds to multiplyring row 3 by 9 (type II). So the inverse
1 0 0
E2−1 = 0 1 0
0 0 19
Example
1 0 5
E3 = 0 1 0
0 0 1
corresponds to adding 5 times row 3 to row 1 (type III). So the inverse
1 0 −5
E3−1 = 0 1 0
0 0 1
A → E1 A → E2 E1 A → · · · → Ek . . . E2 E1 A = B
In other word
A → U B where U = Ek . . . E2 E1 is invertible
U can be computed by
h i h i
A I → B U using the operations carrying A → B
Furthermore
Theorem
A square matrix is invertible if and only if it is a product of elementary
matrices.
Example
" #
−2 3
Express A = as a product of elementary matrices
1 0
Example
" #
−2 3
Express A = as a product of elementary matrices
1 0
Solution
The reduction of A → I is as follow
" # " # " # " #
−2 3 r1 ↔r2 1 0 r2 +2r1 1 0 13 r2 1 0
A= −−−−→ A = −−−−→ −−→ =I
1 0 E1 −2 3 E2 0 3 E3 0 1
" # " # " #
0 1 1 0 1 0
where E1 = , E2 = , E3 =
1 0 2 1 0 31
Hence E3 E2 E1 A = I, so
" #" #" #
0 1 1 0 1 0
A = E1−1 E2−1 E3−1 =
1 0 −2 1 0 3
Table of contents
1 Matrix Addition, Scalar Multiplication, and Transposition
Matrix addition
Scalar multiplication
Transpose of a Matrix
2 Matrix Multiplication
Matrix Multiplication
Application in Computer Graphics
3 Inverse Matrix
Inverse and Linear Systems
An Inversion Method
Application in Cryptography
4 Elementary Matrices
Elementary Matrices
Inverse and Elementary Matrices
5 Elimination equiv LU Factorization
Triangular Matrices
h i
For a matrix A = aij , the elements a11 , a22 , . . . , form the main
diagonal of A.
A is called upper triangular if every entry below and to the left of
the main diagonal is 0
1 −1 0 3
0 0 1 1
0 0 −3 0
Example
Solve the system
x + 2x2 − 3x3 − x4 + 5x5 = 3
1
5x3 + x4 + x5 = 8
2x5 = 6
Solve Ax = b if A is LU-factorizable
A → E1 A → E2 E1 A → · · · → Ek Ek−1 . . . E2 E1 A = U
A = LU
LU-Algorithm
Suppose that A is a m × n matrix of rank r which can be lower reduced to
a row echelon matrix U then A = LU where the lower, invertible matrix L
is constructed as follows:
1 If A = 0 then take L = I
m and U = 0
2 If A ̸= 0 then write A = A and let c be the leading column of A ,
1 1 1
that is the first non zero column from the left in A1 . Use c1 to create
leading 1 and zeros below it using lower reduction. When this is
completed, let A2 be the matrix consisting of rows 2 to m of the
matrix just created
3 If A ̸= 0 then let c be leading columns of A and repeat Step 2 on
2 2 2
A2 to create A3
4 Continue until U is reached
Example
5 −5 10 0 5
−3 3 2 2 1
Find LU-factorization of A =
−2 2 0 −1 0
1 −1 10 2 5
Solution
The reduction to row-echelon form is
Solution (cont)
Let
5 0 0 0
−3 8 0 0
L=
−2 4 −2 0
1 8 0 1
then
A = LU
Practice
2 4 2
Find an LU-factorization for A = 1 1 2
−1 0 2