Download Matrix - MSU CSE

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Matrices
MSU CSE 260
Outline
• Introduction
• Matrix Arithmetic:
– Sum, Product
• Transposes and Powers of Matrices
– Identity matrix, Transpose, Symmetric matrices
• Zero-one Matrices:
– Join, Meet, Boolean product
• Exercise 2.6
Introduction
Definition A matrix is a rectangular array of
numbers.
 a11 a12
a
a22
21

A

 
a
 m1 am 2
 a1n 
 a2 n 

aij
 
 amn 
element in ith row, jth column
m rows
Also written as A=aij
mn matrix
n columns
When m=n, A is called a square matrix.
Matrix Equality
• Definition Let A and B be two matrices.
A=B if they have the same number of rows
and columns, and every element at each
position in A equals element at
corresponding position in B.
Matrix Addition, Subtraction
Let A = aij , B = bij be mn matrices. Then:
A + B = aij + bij, and A - B = aij - bij
1  1 3 4  4 3
 3 4   1  4    4 0 

 
 

2 0  2 3  4 3
1  1 3 4   2  5
 3 4   1  4    2
8

 
 

2 0  2 3   0  3
Matrix Multiplication
Let A be a mk matrix, and B be a kn matrix,
AB  cij 
k
cij   ait btj  ai1b1 j  ai 2b2 j  ...  aik bkj
t 1
 a11
a
 21
a12
a22
a13 
a23 
b11 b12
b
b
 21 22
b31 b32
b13
b23
b33
b14 
 c11 c12

b24  
 c21 c22
b34 
a11b12  a12b22  a13b32  c12
c13
c23
c14 
c24 
Matching Dimensions
To multiply two matrices, inner numbers must match:
Otherwise,
23 34
not defined.
24 matrix
have to be equal
 a11
a
 21
a12
a22
23
a13 
a23 
b11 b12
b
b
 21 22
b31 b32
b13
b23
b33
34
b14 
 c11 c12 c13

b24  
 c21 c22 c23
b34 
24
c14 
c24 
Multiplicative Properties
Note that just because AB is defined, BA may not be.
Example If A is 34, B is 46, then AB=36, but
BA is not defined (46 . 34).
Even if both AB and BA are defined, they may not have
the same size. Even if they do, matrices do not commute.
1 1
2 1
A
B


2
1
1
1




3 2
 4 3
AB  
BA  


5
3
3
2




however ( AB)C  A( BC ),
assuming dimensions match
Efficiency of Multiplication
 a11
a
 21
23
a12 a13 
a22 a23 
34
b12 b13
b11
b
b22
21

b31 b32
b23
b33
b14 
 c11 c12

b24  
 c21 c22
b34 
c13
c23
c14 
c24 
a11b12 + a12b22 + a13b32 = c12
Takes 3 multiplications, and 2 additions for each element.
This has to be done 24 (=8) times (since product matrix is
24). So 243 multiplications are needed.
•(mk) (kn) matrix product requires m.k.n multiplications.
Best Order?
Let A be a 2030 matrix, B 3040, C 4010. (AB)C or A(BC)?
(2030 3040) 4010
20  40 10  8000 operations
20  30  40  24000 operations
32000
2030 (3040 4010)
30  40 10  12000 operations
20  30 10  6000 operations
So, A(BC) is best in this case.
18000
Identity Matrix
The identity matrix has 1’s down the diagonal, e.g.:
1 0 0
I 3  0 1 0 


0 0 1
1 0 0 a
0 1 0   c


0 0 1  e
For a mn matrix A, Im A = A In
mm mn = mn nn
b  a  0  0 b  0  0 
d   0  c  0 0  d  0 
 

f   0  0  e 0  0  f 
Inverse Matrix
Let A and B be nn matrices.
If AB=BA=In then B is called the inverse of A,
denoted B=A-1.
Not all square matrices are invertible.
Use of Inverse to Solve
Equations
a1 a2
b b
2
 1
 c1 c2
a3   x   p 
b3   y    q 
   
c3   z   r 
a1 x  a2 y  a3 z   p 
 b x  b y  b z   q
2
3
 1
  
 c1 x  c2 y  c3 z   r 
1
1
 x  a 1 a 2
 y   b 11 b 12
   1
1
 z   c 1 c 2
a 13   p 

b 13   q 
 
1
c 3   r 
AX  K
A1 AX  A1 K
IX  A1 K
Please note that a-1j is
NOT necessarily (aj)-1.
Transposes of Matrices





 a ji

aij







Flip across diagonal
1 4 
1 2 3
2 5
written At
 4 5 6




3 6
Transposes are used frequently in various algorithms.
Symmetric Matrix
If At  A
 1 4  1
4 3 0


 1 0 2 
In
A is called symmetric.
is symmetric. Note, for A to be
symmetric, is has to be square.
is trivially symmetric...
Examples
( AB) t  B t At
 k

AB  cij    aix bxj 
 x 1

k


t
( AB) t  cij   c ji    a jx bxi 
 x

k
k
k






B t At   b t ix a t xj    bxi a jx    a jx bxi 
 x 1
  x 1
  x 1

Power Matrix
• For a nn square matrix A, the power matrix
is defined as:
Ar = A  A  …  A
r times
• A0 is defined as In.
Zero-one Matrices
• All entries are 0 or 1.
• Operations are  and .
• Boolean product is defined using:
 for multiplication, and
 for addition.
Boolean Operations
1 0 1
0 1 0 
A
B


0
1
0
1
1
0




0
A  B called "meet" A  B  
0
1
A  B called " join" A  B  
1
0
1
1
1
0
0
1
0
Terminology is from Boolean Algebra.Think
“join” is “put together”, like union, and
“meet” is “where they meet”, or intersect.
Boolean Product
A  aij  be m  k , and B  bij  be k  n
A  B  cij  , cij  (ai1  b1 j )  (ai 2  b2 j )    (aik  bkj )
(Should be a ‘dot’)
1 0
1 1 0


A 0 1 , B



0
1
1


1 0
Since this is “or’d”, you
can stop when you find
a ‘1’
(1  1)  (0  0) 1 0 1 1 0
A  B  (0  1)  (1  0) 1 1  0 1 1

 

(1  1)  (0  0) 1 0 1 1 0
Boolean Product Properties
• In general, A  B  B  A
• Example
1 1 0
0 0 1
A  0 1 1 , B  0 0 1




1 1 0
1 1 1
0 0 1
A  B  1 1 1


0 0 1
1 1 0
B  A  1 1 0


1 1 1
Boolean Power
• A Boolean power matrix can be defined in
exactly the same way as a power matrix.
For a nn square matrix A, the power matrix
is defined as:
A[r] = A  A  …  A
r times
A[0] is defined as In.
Exercise 2.6
Related documents