You are on page 1of 28

CE 311 K - Introduction to

Computer Methods

Matrices
Matrices

 Variety of engineering problems lead to the 
need to solve systems of linear equations 
Ax = b

 a11 a12 a13 a1n 


  x1   b1 
     
 a21 a22 a23 a2 n   x2   b2 
A =  x =   b =  
     
     
 am1 am 2 am3  amn   xn   bm 

matrix column vectors


Matrix

 Matrix- a rectangular array of numbers


arranged into m rows and n columns:
 a11 a12 a13 a1n 

 
Rows,  a21 a22 a23 a2 n 
i = 1, …, m
    
 
 am1 am 2 am3  amn 

Columns,
j = 1, …, n
Examples

 These are valid matrices


1 0  a b  1 2 3 
0 1  c e 0 1 0 
     

 These are not


 11 
1 2  4   7 
3  5 6  
   
8 9
 10 
 
Row and Column Matrices (vectors)

 row matrix (or row vector) is a matrix with


one row
r = ( r1 r2 r3  rn )
 column vector is a matrix with only one
column
 c1 
 
c 
c =  2

 
 cm 
Square Matrix

 When the row and column dimensions of a


matrix are equal (m = n) then the matrix is
called square
 a11 a12  a1n 
 
 a21 a22 a2 n 
A =  
 
 
 an1 an 2  ann 
Transportation

 Given a list of cities (or destinations, nodes,


etc) and flights (or roads, connections, etc)
from city a to city b
 Build a square matrix M with the cities
indexing each side of the matrix
– M[a,b] = 1 if there is a connection from a to b
– M[b,a] = 1 if there is a reverse connection from b
to a
– M[a,b] = 0 if there is no connection from a to b
Example

 Albany (A), Boston (B), New  Make a graph of this


York (N), Philly (P), Wash information where vertices
represent cities and every edge
(W), Richmond (R), Detroit represents a flight.
(D), and Las Vegas (L)
– B to N, P, W, D B
B
0
A
0
N
1
P
1
W
1
R
0
D
1
L
0
A 0 0 1 0 1 0 0 0
– A to N, W N
P
1
0
0
0
0
1
1
0
1
1
1
1
1
0
1
0
W 1 1 1 1 0 1 0 1
– N to B, P, W, R, D, L R 0 0 1 1 1 0 0 0
D 1 0 1 0 0 0 0 0
– P to N, B, W, R L 0 0 1 0 1 0 0 0

– W to B, A, N, R, P, L
– R to N, P, W
 Examine the matrix to see if
there is a round trip between
– D to B, N every city that is connected by a
– L to N, W flight.
Matrix Transpose
 The transpose of the (m x n) matrix A is the (n x
m) matrix formed by interchanging the rows and
columns such that row i becomes column i of
the transposed matrix
 a11 a21  am1 
 a11 a12  a1n   
  a a22 am 2 
a a22 a2 n  AT =  12 
A =  21   

 

 
a
 m1 am 2  amn   a1n a2n  amn 
Example - Transpose

1 3 T 1 2
A=  A = 
2 5 3 5

1 0 
1 3 4 
A=  AT = 3 1
0 1 0   
4 0
Matrix Equality

 Two (m x n) matrices A and B are equal if


and only if each of their elements are equal.
That is

A=B
if and only if
aij = bij for i = 1,...,m; j = 1,...,n
Vector Addition

 The sum of two (m x 1) column vectors a and


b is

 a1   b1   a1 + b1 
     
 a  b  a + b2 
a + b =  2 +  2 =  2
   
     
 am   bm   am + bm 
Examples - Vector Addition

1 3
− 3 5
u=  v= 
2  − 1
4 − 2
   

 1   3   1 + 3   4 1  5 
− 3  5  − 3 + 5 2 − 3 − 15
u+v =  +  =  =  5u = 5  =  
 2   − 1   2 − 1  1   2   10 
 4   − 2   4 − 2   2  4   20 
           
Matrix Addition

 a11 a12  a1n   b11 b12  b1n 


   
 a21 a22 a2 n   b21 b22 b2 n 
A + B =   + 
     
   
a am 2  amn  b bm 2  bmn 
 m1  m1
 a11 + b11 a12 + b12  a1n + b1n 
 
 a21 + b21 a22 + b22 a2 n + b2 n 
=  
  
 
a + bm1 am 2 + bm 2  amn + bmn 
 m1
Examples - Matrix Addition

1 2 3   3 2 1
A = 2 1 4 B = − 4 1 2
   
1 4 3  2 3 1 

1 2 3   3 2 1   4 4 4 
A + B =  2 1 4 +  − 4 1 2  = − 2 2 6 
     
1 4 3  2 3 1   3 7 4

 The following matrix addition is not defined


1 2 2 4 6
5 2 + 1 3 5 = ? (not defined!)
   
Scalar – Matrix Multiplication

 Multiplication of a matrix A by a scalar is


defined as  αa11 αa12  αa1n 
 
 α a α a α a 2n 
αA =  21 22

 
 
 αam1 αam 2  αamn 
 Examples
1 2 4 8 
α = 4, A=  , αA =  0 4 
 0 1   

1 4 1  − 2 − 8 − 2
α = −2, A =   , αA =  − 4 0 − 6 
 2 0 3  
Matrix – Matrix Multiplication
 The product of two matrices A and B is defined only
if
– the number of columns of A is equal to the number of rows
of B.
 If A is (m x p) and B is (p x n), the product is an (m x
n) matrix C
C mxn = Amxp B pxn
Matrix – Matrix Multiplication

 a11 a12  a1 p  b11 b12  b1n 


  
 a21 a22 a1 p  b21 b22 b1n 
C = AB = 
       
  
 am1 am 2  amp  b p1 b p 2  b pn 
  
 a11b11 +  + a1 p b p1 a11b12 +  + a1 p b p 2  a11b1n +  + a1 p b pn 
 
 a21b11 +  + a2 p b p1 a21b12 +  + a2 p b p 2 a21b1n +  + a2 p b pn 
=  
  
 
 am1b11 +  + amp b p1 am1b12 +  + amp b p 2  am1b1n +  + amp b pn 
 
p
cij = ∑ aik bkj
k =1
Example - Matrix Multiplication

 b1 
 
a = (a1, a2 ,, an )  b2 
b= 

  c1x1 = a1xn bnx1 (scalar)
 bn 

 b1 
 
 b2 
c = a ⋅ b = (a1, a2 ,, an )  = a1b1 + a2b2 +  + an bn

 
 bn 
Example - Matrix Multiplication

 a11 a12  a1n   b1 


a  
21 a22  a2n   b2 
A=  b= 
   
a    c nx1 = Anxn bnx1
 n1 an 2  ann   bn 

 a11 a12  a1n  b1  a11b1 + a12b2 +  a1n bn


a   
 21 a22  a2n   b2  a11b1 + a22b2 +  a2n bn
c = Ab =   =
   
a   
 n1 an 2  ann  bn  an1b1 + an 2b2 +  ann bn
Example - Matrix Multiplication

1 3   2 1
A=  B= 
2 4 3 5

C 2 x 2 = A2 x 2 B2 x 2

1 3 2 1  1 ⋅ 2 + 3 ⋅ 3 1 ⋅1 + 3 ⋅ 5  11 16 
C = A⋅ B =     =  = 
2 4 3 5 2 ⋅ 2 + 4 ⋅ 3 2 ⋅1 + 4 ⋅ 5 16 22
Example - Matrix Multiplication

1 2 3  2 1 
A =  2 1 4 B = 1 2 
   
1 4 3 2 1 

1 2 3   2 1 
C = A ⋅ B =  2 1 4 1 2
C 3 x 2 = A3 x3 B3 x 2
  
1 4 3 2 1 
1 ⋅ 2 + 2 ⋅1 + 3 ⋅ 2 1 ⋅1 + 2 ⋅ 2 + 3 ⋅1 10 8 
= 2 ⋅ 2 + 1 ⋅1 + 4 ⋅ 2 2 ⋅1 + 1 ⋅ 2 + 4 ⋅1 = 13 8 
   
1 ⋅ 2 + 4 ⋅1 + 3 ⋅ 2 1 ⋅1 + 4 ⋅ 2 + 3 ⋅1 12 12
Example - Matrix Multiplication

3 0  4 7 
B=
A = 1 1  
6 8 
 
5 2
C 3 x 2 = A3 x 2 B2 x 2

3 0  12 21
  4 7 
C = A⋅ B = 1 1   = 10 15
  6 8   
5 2 32 51
Diagonal Matrices

 a11 0 0 0 
 
 0 a22 0 0 
A = 
 Diagonal Matrix 0 0  0 
 
 0 0 0 ann 

 Tridiagonal Matrix  a11 a12 0 0 0 


 
 a21 a22 a23 0 0 
A =  0 a32  0 
 
 0 0   a45 
 0 0 0 a54 a55 

Identity Matrix

 Identity Matrix
1 0 0 0
0 1 0 0
I = 
0 0 1 0
0 0 0 1
 
 The identity matrix has the property that
if A is a square matrix, then

IA = AI = A
Matrix Inverse

 If
A is an (n x n) square matrix and there is a
matrix X with the property that AX = I

X is defined to be the inverse of A and is


denoted A-1

AA−1 = I A−1 A = I
AA −1 = I
Example - Matrix Inverse

• Example (2 x 2) matrix

 a11 a12 
A = 
a a
 21 22 

1  a22 − a12 
A−1 =
a11a22 − a12 a21 − a21 a11 
Special Matrices

u11 u12 u13 u14 


  0 u22
 u23 u24 
 Upper Triangular Matrix U= 
 0 0 u33 u34 
 0 0 0 u44 

 Lower Trangular Matrix  L11 0 0 0 


  L21 L22
 0 0 
L= 
 L31 L32 L33 0 
L L44 
 41 L42 L43

You might also like