MATH3322 2 Basic Linear Algebra and Matrix Operations
MATH3322 2 Basic Linear Algebra and Matrix Operations
Notations:
e.g a b X Y
Vectors: bold lower case letters in printing (standard lower case letters in hand-writing with
vector notation).
iiaiipfor
or dropped
the ith entry of a
simplicity
where ai are scalars
ā a di an
Vector spaces: R c
Real
spaces will be assumed if not specified
Special vectors:
ēi 1
f
length-n basis vector:
the ith component
Matrices: bold upper case letters in printing (standard upper case letters in hand-writing).
ㄨm ㄨm
An nxm matrix A ER for A Ec
called element
A caijinxm
or dropped
or A
1 or entry
an dnz anm
for simplicity
where Qij ER for CI for i 1 n j 1
Special matrices:
m I.
Identity matrix
ii
o inn
Matrix spaces: Rmxn cmxn
i.e ā ER
R R
and c cn
the
Similarly space of all length n row vectors is R'ㄨ or4
m
Any matrix A ER for cnxmg can be written in a column vector form as
A ān ān
where ER or ai
c j 1 m are columns of
Similarly, we can also write RnXm A AE in a row column vector form as
orcnxm A
㒞式
where ācil E Rm 1or 4m i 1 n are rows of A
Matrix transpose:
A Iaijlnxm A G mxn
Example
A
1 剿
A
lāqgi
ㄨm
If A ER then At AT
ㄨm
If A E4 then A AT
A ER is symmetric if A AT
ㄨ
A E4 is Hermitian if A At
Example A 1 is symmetric
121 31
Hermitian
ft I
A is
an bnianztbuzii.am bnm
2) Scalar product
Xm
Let be a scalar and AER be a matrix. The scalar product of c and A, denoted
ER
by B, is in Rnxm and given by
B CA can cazm
1921 i
can canz canm
pseudo code:
for i 1 n
for j 1 m
end end
ji loop
ij loop
B is obtained Column
by colum
B is obtained row by row
Remark: The two implementations may have di erent performances, depending on how the
matrices are stored. If the matrices is stored row-by-row, then ij-loop may be better, because it
R ca
叫
their inner product is
b aibi
pseudo code:
inner_prod 0
for i 1 n
4) Matrix-Vector product:
• Let A=
aij mxn E RM and x= Xi nx ER
Then the matrix-vector product of A and x, denoted by b, is a vector in , given by
R
5 器i.iii.in
l Hǎiiiit i
amxitdmzxz
测
9mn加
then
5 A
iàiii
州 州
āǎi
āmix̅ aim
i.e. entries of 万 are inner products of row vectors āi and x̅
This gives an implementation of b=Ax
pseudo code 1:
ij-loop i l
for m
bi 0
end
ji loop for j 1 n
for i l m
add to by jail
i bit xjaij
end
end
ij loop ji loop
row-wise,
ij loop is better
5) Matrix-Matrix product
C
Cij E Rm where Cij 葥aikbkj
n
n
Pj
m m
贸
A
ithrǐǐ Bjthidumn C
lineout
it
• Obviously, inner product and matrix-vector product are special cases of matrix-matrix
product.
for i li m
for j 1 P
for j l P for i li m
Ci 0 Cij 0
j
for k l in for k 1in
end end
ijk loop jik loop
A 1āin an
fÜl叩
ācm B
Then
C AB ānai Ü
any 䄗
箭 āim 151k
We get another implementation
Initialize matrix C 0
for k l in
for i l m
end
end
kij loop
• Computational Complexity
flops
1) Inner product: Given a, b. , what is the complexity for <a,b>?
ER
<a,b>= aibi
inner_prod 0
for i 1 n
11 11 2n O n
iigo
What is O(n)?
2) Matrix-Vector product of E Rm
X
A x ER
for i l m
yi 0
for j lin
yi y i t
aijxj
end
end
器 2
Number
of flops 器
信 1 1 是 2n 2mn 三 0 mn
XP
3)Matrix-Matrix product AE Rmx BE R
C=AB E Rm with Cij Ědikbkj i 1 m j 1 p
for i l m
for j 1 P
in
bfāfl
en
end
end
Number
of flops
11 哥哥 2 哥哥 zn
Ě 1哥 10 1
In particular if m n p then
ㄨ
A ER BE R and C AB costs 2m O n3
1) loop ordering
e.g. the fastest matrix-matrix product algorithm is O(n2.32 ), people guess that the best
3)The e ciency depends not only on computational complexity, but many other issues.
• All these basic matrix computation subroutines come with your computer. We don’t need to
CuBLAS
X
AERm
n The blocks in the same
An A A19
row should have the
A
f Azi Azz
Api Apz
A29
Apq
IN same number of rows
columns
have the same number of
They
where
Aij ER are sub_matrices of A and mit m
p m
n that tnq n
We call it a partition of A
Example: A
品 品 ER
lǎii
931 932 933
ˋ
iq
A
9
lǎii
器
们 Ayǎi 2
931A292 㠮 启
A valid matrix partition Not a valid matrix partition
• Matrix additions, multiplications, transpose in matrix partition forms are formally the same as
c) Multiplication: B
A Aij ij Bij ij
Then AB AikBkj provided AikBkj are well
defined AE
Example: We usually write
Let x̅ e Rn be a vector
1劐
because
xj is a scalar
Then
此
A x̅ āin an ām
1劐 哥āg xj 房xjāij
and partition A, B by
B of rows of B
ER are transpose
rj
虌成
4萨
5
Then āini
āinām
鬬
C AB
of āik and 5k
C is the sum of outer products
Partition A B in
A 品
fǜi
where ā ER are transpose of rows of A
Then AB āi bin
f
kā 万51
bptn.bg ij
ddjikn
i ㄒ
the ci j th entry of C is the inner product of
i throw of A and j th column
of B
Ran A A x̅ I x̅ ER
āgilx ER Rm
Col AI
It is a subspace of Rm
• The null space of A is
NullAl x ER I Ax̅ 0了 R
kerA
• The rank of A is
To measure how accurate our algorithm is, we need to de ne metric, i.e., distance between
yl ci
• Metric for vectors
For two vectors b ER , we need to generalize the absolute function for scalars to
vectors.
2)
Ixy1 1Allyl x YER
3)
Ixtyl IN 1YI x y ER
—Norm: a generation of absolute value to vectors.
De nition: A function
R 1 R , denoted by ||x|| for any x̅ER , is called a norm, if it
b) Condition 2) says that the norm of a scaling of vectors is the scaling of the norm.
戏
zi Nxx̅ll 1α111 11
11TH Ixil x̅ ER
11 11 0 年1xil 0
lxil 0 i xi 0 7
Example 3: Max norm ( v0 -norm) x̅ Ō
11αx̅11 1Xxil 点IN Ixi
11TH o nmyn IXil x̅ER
1α1 lxil 12111x11
Example 4: p-norm (p>= 1)
11 J11 产1Xityil
Let p be a positive integer Define 平lxiltlyil 严刚 平以
声
11x̅llp 1XiP 万11 11511
11
不511
y i 111
iillx y
lb. l 3
11不511
X
De nition: A function R R denoted by 11All for any AERm , is called a norm, if it
satis es: 1) IIAll 0 A ERm and IIAll 0 A 0
A Rm R ts Rm
x̅ 1 A x̅
11A1h
荷肾
器
In other words, matrix p-norm of A is the largest magnifying factor of A acting from R with
Theorem:
IIAllp 11Ax̅llp
朤
Example 1: 2-norm
āmai ām 了 11 11Ěixiāugll
11AAll 11
劐
triangle inequality
剖xiācnll
Ei In111ācc 11
1M ngn11可111
11不 my11ill
ny.liājill
Hence 11Aill
my llāij 11
for any 11N 1
Taking over all x̅ satisfying 11 11 1
11A I
朤 gnllāill
Now we prove
然
11AN
gn11可11
Let j ie 11aj.lt
ǐǎynllāill
arggllāgill
my llāiill
Then llltei.tl 11āijn11
11Ill ǐrzgynllejll 1
Example: -norm
For the matrix p-norm, besides 1),2) and 3) in the de nition of matrix norm, the matrix p-norm