Arrays and Matrices

Download Report

Transcript Arrays and Matrices

Matrices
CE 311 K - Introduction to Computer
Methods
Daene C. McKinney
Introduction
• Matrices
• Matrix Arithmetic
– Addition
– Multiplication
• Diagonal Matrices
– Identity matrix
• Matrix Inverse
Matrix
• Matrix - a rectangular array of numbers
arranged into m rows and n columns:
Rows,
i = 1, …, m
 a11 a12

 a21 a22
 

 am1 am 2
a1n 

a2 n 

 

am3  amn 
a13
a23
Columns,
j = 1, …, n

Matrices
• Variety of engineering problems lead to the
need to solve systems of linear equations
Ax  b
 a11 a12

 a21 a22
A  


 am1 am 2
matrix
a1n 
 x1 
 b1 
 
 

a2 n 
 x2 
 b2 
x    b   





 
 

am3  amn 
 xn 
 bm 
a13
a23

column vectors
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 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 


a2 n 
 a21 a22
A  





 an1 an 2  ann 
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 a12  a1n 


a
a
a

22
2n 
A   21





a
a

a
 m1 m 2
mn 
 a11

a
AT   12


 a1n
a21  am1 

a22
am 2 



a2n  amn 
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
+
b
 
 

2 
a  b   2   2   2




 
 


 am 
 bm 
 am + bm 
Matrix Addition
 a11

a
A  B   21


a
 m1
a12
a22
am 2
 a1n 
 b11 b12


a2 n 
 b21 b22

 
  



b
 amn 
 m1 bm 2
 b11 a12  b12 
 b21 a22  b22
 a11

a
  21


a  b
m1
 m1
am 2  bm 2
 b1n 

b2 n 
  

 bmn 
a1n  b1n 

a2 n  b2 n 




 amn  bmn 
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
Cmxn  Amxp B pxn
Matrix Multiplication
 a11 a12  a1 p  b11 b12  b1n 



a1 p  b21 b22
b1n 
 a21 a22
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 


a21b1n    a2 p b pn 
 a21b11    a2 p b p1 a21b12    a2 p b p 2
 






 am1b11    amp b p1 am1b12    amp b p 2  am1b1n    amp b pn 


Example - Matrix Multiplication
1 2 3   2 1 
C  A  B   2 1 4  1 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
3 0
12 21
4 7 


C  A B  1 1 
 10 15


 6 8  

5 2
32 51
Diagonal Matrices
0
0 
 a11 0


0 
 0 a22 0
A  
0
0  0 


0
0 ann 
 0
• Diagonal Matrix


Identity Matrix
The identity matrix has the
square matrix, then
1 0 0
0 1 0
I
0 0 1
0 0 0
 if A is
property that
IA  AI  A
0
0

0

1
a
Matrix Inverse
• If A is a 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
A1 A  I
AA1  I
• Example 2x2 matrix inverse
 a11 a12 
A 

a21 a22 
A1 
 a22  a12 
1
a11a22  a12 a21  a21 a11 
Summary
• Matrices
• Matrix Arithmetic
– Addition
– Multiplication
• Diagonal Matrices
– Identity matrix
• Matrix Inverse