Lecture4 MatrixAlgebraV2
Lecture4 MatrixAlgebraV2
FN 211
The matrix from past to present
• Calculating yields of grain: From
Babylon to Han Dynasty
3
hai ลอ
ลไ ปลา
Sample text (put this in
104y แล้
https://www.wordclouds.com/)
้
นี
ใน www.
5
Our class today
• Vector and matrices representations
• Vectors and matrices operations
• Matrices applications
– Solving linear equations
– Portfolio return and risks
– Financial modeling
6
REPRESENTATIONS OF
VECTORS AND MATRICES
7
Vector in R-space
• A vector is an ordered finite list of numbers
usually represented as a vertical array
surrounded by brackets as in,
0 .5
v 3 .0
4.2 31
• The vertical array above has 3 row entries
and one column. It is called a vector in 3
8
Geometric description of vectors
9
Geometric description of vectors
10
Reducing lengthy explanations
to vectors
• Denote as a sample space of all possible
states of nature with elements (1, 2, ..m).
• A vector that lists all the possible cash flow
payoffs for project X under different scenarios
will be (X(1), X(2),…, X(m)).
• Let (Bad, Base, Best)
11
Vector representation of cash
flow outcomes
• Project X yields three possible cash flow
outcomes:
Outcome Cash flows (THB mn)
Bad -50
Base 75
Best 120
Document 1
No. of positive words 27
No. of negative words 3
No. of neutral words 0
13
Feature or attribute vector of a
credit card client
Feature/Attribute Quantities/Description
Gender F
Education Bachelor’s
Age 21
Monthly Salary 30,000
Monthly average spending 10,135
14
Vector of time series stock
returns
Time TFMAMA
Day 1 0.012
Day 2 -0.052
….
Day 30 0.026
15
Special vectors to help with algebra and
computational analytics
• A zero vector is a vector with all elements equal to zero. We can denote a
zero vector with n elements as 0n. Often times, the dimensions of the zero
vector is left out leaving us to figure out from the context the dimension.
• A unit vector is a vector with all elements equal to zero, except one element
which is equal to one. A unit vector with the ith element of one is denoted ei.
For example,
1 0
e1 0 e2 1
0 0
• Transpose vector: Vector with rows and columns switched.
• For example let’s transpose vector v from slide 10
a11 , , a1n
a 21 , , a 2 n
A
am1 , , amn mn
17
Matrix representation
• A dietitian in a hospital is to arrange a special diet using three basic foods.
The diet is to include exactly 340 units of calcium, 180 units of iron, and 220
units of vitamin A. The number of units per ounce of each special ingredient
for each of the foods is indicated in the table. How many ounces of each
food must be used to meet the diet requirements
18
Recall the ancient problem of grain yields
19
Special types of matrices
• Square matrix: A matrix with equal number of columns and rows.
a11 a12
A22
a a
21 22
• Identity matrix: A square matrix with all elements in diag equal to
one and zero elsewhere. 1 0 0
I 3 0 1 0
0 0 1
2 / 3 2 / 6
1 / 21 / 2 1 / 4
2 / 5 1 / 5
22
Working with vectors
• Inner product (dot product)
T
1 1 1
3 1 1 3 5 1 11 31 05 2
5 0 0
23
Fun things you can do with unit vectors
0 1
• Let’s define 0 2
e3 1 w 3
0 4
0 5
24
Matrix addition/subtraction
25
Multiplication by number
• The product of a number k and a matrix M, denoted by kM, is a matrix
formed by multiplying each element of M by k.
26
Example
27
28
Properties of matrix addition and scalar
multiplication
29
Transpose of a matrix
a11 a12 a1n
a a22 a2 n
If A 21 M mn
a am 2 amn
m1
30
Ex 8: (Find the transpose of the following
matrix) 1 2 3 0 1
2
(a) A (b) A 4 5 6 (c) A 2 4
8
7 8 9 1 1
Sol: (a)
2
A AT 2 8
8
(b) 1 2 3 1 4 7
A 4 5 6 AT 2 5 8
7 8 9 3 6 9
(c) 0 1
0 2 1
A 2 4 A
T
1 4 1
1 1 31
Properties of transposes
(1) ( AT )T A
(2) ( A B)T AT BT
(3) (cA)T c( AT )
(4) ( AB)T BT AT
32
Matrix multiplication
• Definition 1
33
Matrix multiplication
• Definition 2
34
Matrix product
35
Commutative law does not work in
matrix multiplication
1 3 2 1
A and B
2 1 0 2
Sol:
1 3 2 1 2 5
AB
2 1 0 2 4 4
2 1 1 3 0 7
BA
0 2 2 1 4 2
Note: AB BA
36
The identity matrix
and inverse matrices
37
Inverse of a 2x2 matrix
38
Example Find Inverse of A
Step 1 – Calc Determinant known as det|A|
4 8 Determinant (ad-cb) = 4x3-8x1 = 4
A
1 3
3 8
step2
Step 2 – Swap Elements on leading diagonal 1 4
3 8
step3
Step 3 – negate the other elements 1 4
1 3 8
step4
Step 4 – multiply by 1/determinant 4 1 4
check
4 8 0.75 2
1 0.75 2 AA
1
0.25 1
A
1 3
0.25 1
3 2
0.75 0.75
8 8
1 0
0 1
23
39
Find the inverses and check them
5 20 1 2 20 0.2 2
1
B B
1 2 10 1 5 0.1 0.5
2 2 1 1 2 0.5 1
C 1
C
0 1 2 0 2 0 1
40
Inverse of n x n matrix
• Step 1: Write augmented matrix
41
-
↓ li
/
/
%
:
I
2 1 2
-
I
:
⑤
1 1 -
% inter /
- R1 + &3 · " &
2 2
% 2
( /
&3 + &2 1 = 1
Me (
2 =04 213 + % &
% -
⑧ 2 อ · :
1
& = 1 -1 3 3 3
↑"
8 1 ซ
#
-2
-
: :I g
-
-R 2 + Re # 2
⑧ 1 อ -C
I = % -2
% 0 &
-
Inverse of n x n matrix
/
42
Algebra properties of invertible matrices
43
MATRIX APPLICATIONS
44
Ways to solve linear systems
• Row reductions with augmented matrices
(Gauss Jordan elimination similar to the
ancient techniques used by Babylonians
and Chinese)
• Use a matrix inverse to multiply through
the system.
• Problems: Solutions not always exist
45
Solving system of equations with
reduced matrices (Not tested)
• How do we solve….
② number
unige solutio
m
pinfinit
~ขา ให
~มี
เลย !
~
&7
%
x= +1 + M. X2 : /
จิ ง้ snumb
·
↓
· ·0 ° no solution
·คือม
• Forms 1, 2, and 3 above represent systems that have, respectively, a ↓ม
ตัวแปรเลย
unique solution, an infinite number of solutions, and no solution.
R
X, + M -X 2 :
ต้อแบ รท
ทา
ี
46
Augmented matrix with no
solution (not tested)
• x+ 2y = 4
• 2x +4y = 8
1 2 4
2 4 8
A reduced form from (-2)R1 +R2 R2 results in
1 2 4
0 0 0
47
Example: Solving equations with reduced
matrix (not tested)
• Solve
2 -6
48
Solving with linear systems with invertible Matrices (On
test: Know how to set up and solve for 2 variables)
49
No arbitrage price
• Simultaneous buying and selling of commodities, fx,
securities, or derivatives in order to take advantage of
different prices of the same assets.
• Law of one price: In frictionless markets (no transaction
costs), the same asset should trade at the same price.
• An Indian pomegranate costs THB 50, then 3
pomegranates should cost THB 150.
• What if they cost THB 151 or THB 149 in another
market?
50
Fruit bundles: Evaluate arbitrage free price
for orange and melon
• Bundle A:
• Bundle B:
•
A X= B
# =- A #
2 po pm 150 2 1 p0 150
1
p0 2 1 150
7 po 3 pm 470 7 3 pm 470 pm 7 3 470
52
Rank of a matrix
• The Rank of a Matrix. The number of non-zero
rows in a reduced form matrix.
• Example 1
1 2 1 2
• Example 2
3 4 1 4
④ ②
1 2 2 1
• Example 3
4 8 1 0.5
& &
53
Linear independence vs linear
dependence
• A set of vectors is linearly independent if none of them can be
written as a linear combination of the others
1 1 1 "ไม ม ค ม 54
มี
ำ
Linear systems dependence
• Consider the linear systems
System Equations
=
1 x -2y = 2
i =5
x+y=5
A"D
idependen inde -> Unique sof A=
2 x+ 2y = -4 Moso
-1
2x +4y = 8
idependen
t
3 X + 2y = 4 &x2 = Re
!1.
2x + 4y =8
dependen
#
dep
Independent = ด
dependent = MIN'YG
55
Graph solutions
System 1 System 2
10 4
3
x + y =5 8
2
2x + 4y = 8
6 1
0
4 -4 -3 -2 -1 -1 0 1 2 3 4 5 6
2 x + 2y = -4 -2
-3
0
-4 -3 -2 -1 0 1 2 3 4 5 6 -4
-2 -5
x -2y = 2
-4 Series1 Series2
System 3
4
3.5
3
2.5
2x + 4y = 8
2
x + 2y = 4
1.5
1
0.5
0
-4 -3 -2 -1 0 1 2 3 4 5 6
-0.5
-1 56