Matrix Operations
Matrix Operations
Lecture 3
Matrix Operations
Marco Chiarandini
Department of Mathematics & Computer Science
University of Southern Denmark
Matrices
Vectors
Vectors and Matrices
Outline More on Linear Systems
1. Matrices
2. Vectors
2
Matrices
Vectors
Vectors and Matrices
Outline More on Linear Systems
1. Matrices
2. Vectors
3
Matrices
Vectors
Vectors and Matrices
Matrices More on Linear Systems
Definition (Matrix)
A matrix is a rectangular array of numbers or symbols. It can be written as
a11 a12 · · · a1n
a21 a22 · · · a2n
.. .. . . ..
. . . .
am1 am2 · · · amn
• The size of A is m × n.
4
Matrices
Vectors
Vectors and Matrices
More on Linear Systems
• A square matrix is an n × n matrix.
• The diagonal of a square matrix is the list of entries a11 , a22 , . . . , ann
• The diagonal matrix is a matrix n × n with aij = 0 if i 6= j (ie, a square matrix with all the
entries which are not on the diagonal equal to 0):
a11 0 · · · 0
0 a22 · · · 0
.. .. . . ..
. . . .
0 0 · · · amn
Definition (Equality)
Two matrices are equal if they have the same size and if corresponding entries are equal. That is, if
A = (aij ) and B = (bij ) are both m × n matrices, then:
A = B ⇐⇒ aij = bij 1 ≤ i ≤ m, 1 ≤ j ≤ n
5
Matrices
Vectors
Vectors and Matrices
Matrix Addition More on Linear Systems
Definition (Addition)
If A = (aij ) and B = (bij ) are both m × n matrices, then
A + B = (aij + bij ) 1 ≤ i ≤ m, 1 ≤ j ≤ n
matrix A matrix B
+ + +
a11 a12 · · · a1n b11 b12 · · · b1n
a21 a22 · · · a2n b21 b22 · · · b2n
+
.. ... .. . .. .. . . ..
Eg:
. . ..
. . . .
am1 am2 · · · amn bm1 bm2 · · · bmn
3 1 2 −1 1 4
A+B = + =?
0 5 −2 2 −3 1
c11 c12 · · · c1n
c21 c22 · · · c2n
.. .. .. .
element-wise operation
. . . ..
cm1 cm2 · · · cmn
matrix C = A + B 6
Matrices
Vectors
Vectors and Matrices
Scalar Matrix Multiplication More on Linear Systems
λA = (λaij ) 1 ≤ i ≤ m, 1 ≤ j ≤ n
Eg:
−2A =?
element-wise operation
7
Matrices
Vectors
Vectors and Matrices
Matrix Multiplication More on Linear Systems
Two matrices can be multiplied together, depending on the size of the matrices
b1j
b2j
.. What is the size of C?
ai1 ai2 · · · ain .
bnj
8
B : p rows q columns
b 11 ... b1 j ; ... b 1q
.. .. .. ..
..
. . . . .
b k1 ... bk j ; ... b kq
1j
b
×
i1
.. .. .. .. ..
a
+
. . . . .
..
.+
j
bk
×
k b p1 ... bp j ; ... b pq
ai
+
..
.+
j
×
bp Not an element-wise
p
ai
operation!
a 11 ... a 1k ... a 1p c 11 ... c1 j ... c 1q
.. .. .. .. .. .. .. .. .. ..
. . . . . . . . . .
ai 1 ; ... ai k ; ... ai p ; ci 1 ... ci j ; ... ci q
.. .. .. .. .. .. .. ..
.. ..
. . . . . . . . . .
a n1 ... a nk ... a np c n1 ... c nk ... c nq
1 1 1 3 4
2 3 0
0 1 5 3
AB =
1
1 1 =
2 4 1 14
−1 3
2 2 −1 9 −1
The motivation behind this definition is that it allows to deal conveniently with several tasks in
linear algebra. Think about the way we rewrote a system of linear equations using this definition.
10
Matrices
Vectors
Vectors and Matrices
More on Linear Systems
3 1
2 1 3
A= B = 1 0 AB is 2 × 2 and BA is 3 × 3
1 2 1
1 1
1 2 1 1
A= B= ok sizes but AB 6= BA
3 4 0 1
11
Matrices
Vectors
Vectors and Matrices
Matrix Algebra More on Linear Systems
Matrices are useful because they provide compact notation and we can perform algebra with them
Bear in mind to use only operations that are defined. In the following rules, the sizes are dictated
by the operations being defined.
• commutative A + B = B + A . Proof?
• associative:
• (A + B) + C = A + (B + C )
• λ(AB) = (λA)B = A(λB) Size?
• (AB)C = A(BC )
• distributive:
• A(B + C ) = AB + AC
• (B + C )A = BA + CA Why both first two rules?
• λ(A + B) = λA + λB
12
Matrices
Vectors
Vectors and Matrices
Zero Matrix More on Linear Systems
• additive identity: A − A = 0
• A+0=A
• A−A=0
• 0A = 0, A0 = 0
13
Matrices
Vectors
Vectors and Matrices
Identity Matrix More on Linear Systems
A of size m × n.
What size is I ?
• AI = A and IA = A
the identity matrix must be a square
matrix
Exercise: 3A + 2B = 2(B − A + C ) 14
Matrices
Vectors
Vectors and Matrices
Matrix Inverse More on Linear Systems
0 0 1 −1 8 0
A= , B= , C=
1 1 3 5 −4 4
0 0
AB = AC =
4 4
but hold on, this might be just a lucky case
• A + 5B = A + 5C =⇒ B = C
addition and scalar multiplication have inverses (−A and 1/c)
15
Matrices
Vectors
Vectors and Matrices
Inverse Matrix More on Linear Systems
AB = BA = I
where I is the n × n identity matrix. The matrix B is called the inverse of A and is denoted by A−1 .
1 2 −2 1
A= , B=
3 4 3/2 −1/2
Theorem
If A is an n × n invertible matrix, then the matrix A−1 is unique.
• If
a b
A= , ad − bc 6= 0
c d
then A has the inverse
1 d −b
A−1 = ad − bc 6= 0 check that this is true
ad − bc −c a
A−1 AB = A−1 AC =⇒ IB = IC =⇒ B = C
18
Matrices
Vectors
Vectors and Matrices
Properties of the Inverse More on Linear Systems
• (A−1 )−1 = A
• (λA)−1 = 1 −1
λA
the inverse of the matrix (λA) is a matrix C that satisfies (λA)C = C (λA) = I .
Using matrix algebra:
1 −1 1 1 −1 1
(λA) A = λ AA−1 = I and A (λA) = λA−1 A = I
λ λ λ λ
• (AB)−1 = B −1 A−1
19
Matrices
Vectors
Vectors and Matrices
Powers of a matrix More on Linear Systems
Ar = AA . . . A}
| {z
r times
• Ar As = Ar +s
• (Ar )s = Ars
20
Matrices
Vectors
Vectors and Matrices
Transpose Matrix More on Linear Systems
Definition (Transpose)
The transpose of an m × n matrix A is the n × m matrix B defined by
It is denoted AT
a11 a12 · · · a1n a11 a21 · · · am1
a21 a22 · · · a2n a12 a22 · · · am2
A = (aij ) = . .. .. . AT = (aji ) = . .. .. .
.. . . .. .. . . ..
am1 am2 · · · amn a1n a2n · · · anm
1 0 1 3
We reflect the matrix about its main diagonal
3 1 0 1
• (AT )T = A
• (λA)T = λAT
• (A + B)T = AT + B T
• (AB)T = B T AT (consider first which matrix sizes make sense in the multiplication, then
rewrite the terms)
22
Matrices
Vectors
Vectors and Matrices
Symmetric Matrix More on Linear Systems
23
Matrices
Vectors
Vectors and Matrices
Outline More on Linear Systems
1. Matrices
2. Vectors
24
Matrices
Vectors
Vectors and Matrices
Vectors More on Linear Systems
• For a fixed n, the set of vectors together with the operations of addition and multiplication
form the set Rn , usually called Euclidean space
v = α1 v1 + α2 v2 + · · · + αk vk
the inner product denoted hv, wi, is the real number given by
* v1 w1 +
v2 w2
hv, wi = . , . = v1 w1 + v2 w2 + . . . + vn wn = vT w
.. ..
vn wn
w2
vT w = v1 v2 · · · vn . = v1 w1 + v2 w2 + . . . + vn wn
.
.
wn
Theorem
The inner product
hx, yi = x1 y1 + x2 y2 + · · · + xn yn , x, y ∈ Rn
• hx, yi = hy, xi
• α hx, yi = hαx, yi = hx, αyi
• hx + y, zi = hx, zi + hy, zi
• hx, xi ≥ 0 and hx, xi = 0 if and only if x = 0
1. Matrices
2. Vectors
29
Matrices
Vectors
Vectors and Matrices
Vectors and Matrices More on Linear Systems
Let A be an m × n matrix
· · · a1n
a11 a12
a21 a22 · · · a2n
. .. .
.. ..
. . ..
am1 am2 · · · amn
Ax = x1 a1 + x2 a2 + . . . + xn an
31
Matrices
Vectors
Vectors and Matrices
Outline More on Linear Systems
1. Matrices
2. Vectors
32
Matrices
Vectors
Vectors and Matrices
Solution Sets of Linear Systems More on Linear Systems
Theorem
A system of linear equations either has no solution, a unique solution or infinitely many solutions.
Proof.
Let’s assume the system Ax = b has two distinct solutions p and q, that is:
Ap = b Aq=b p − q 6= 0
Then:
that is, v is a solution of Ax = b and since p − q 6= 0 and there are infinitely many choices for t,
then there are infinitely many solutions for Ax = b.
33
Matrices
Vectors
Vectors and Matrices
More on Linear Systems
{x | Ax = b} = {p + z | z ∈ N(A)}.