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 a21 a22 A = am1 am 2
matrix
a1n x1 b1 a2 n x2 b2 x = b = am3 amn xn bm a13 a23
column vectors
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 a23 a2 n am3 amn a13
Columns, j = 1, …, n
Examples These
are valid matrices 1 0 0 1
These
a b c e
1 2 3 0 1 0
are not
1 2 3
4 5 6
11 7 8 9 10
Row and Column Matrices (vectors) row
matrix (or row vector) is a matrix with one row r = ( r1 r2
column
r3 rn )
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 a2 n a21 a22 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
– – – – – – – –
B to N, P, W, D A to N, W N to B, P, W, R, D, L P to N, B, W, R W to B, A, N, R, P, L R to N, P, W D to B, N L to N, W
Make a graph of this information where vertices represent cities and every edge represents a flight.
Albany (A), Boston (B), New York (N), Philly (P), Wash (W), Richmond (R), Detroit (D), and Las Vegas (L)
B 0 0 1 0 1 0 1 0
B A N P W R D L
A 0 0 0 0 1 0 0 0
N 1 1 0 1 1 1 1 1
P 1 0 1 0 1 1 0 0
W 1 1 1 1 0 1 0 1
R 0 0 1 1 1 0 0 0
D 1 0 1 0 0 0 0 0
Examine the matrix to see if there is a round trip between every city that is connected by a flight.
L 0 0 1 0 1 0 0 0
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 a A = 21 a m1
a12
a22 am 2
a1n a2 n amn
a11 a21 am1 a22 am 2 a AT = 12 a1n a2n amn
Example - Transpose 1 3 A= 2 5
1 3 4 A= 0 1 0
1 2 T A = 3 5
1 0 AT = 3 1 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 + b 2 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 − 3 5 − 3 + 5 2 = u+v = + = 2 − 1 2 − 1 1 4 − 2 4 − 2 2
1 5 − 3 − 15 5u = 5 = 2 10 4 20
Matrix Addition a11 a21 A + B = a m1
a12 a22 am 2
a11 a21 = a m1
a1n b11 a2 n b21 + b amn m1 + b11 a12 + b12 + b21 a22 + b22 + bm1 am 2 + bm 2
b12 b22 bm 2
b1n b2 n bmn
a1n + b1n a2 n + b2 n amn + bmn
Examples - Matrix Addition 1 2 3 A = 2 1 4 1 4 3
3 2 1 B = − 4 1 2 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
defined as
Examples
of a matrix A by a scalar is αa11 αa12 αa1n α a α a α a 22 2n αA = 21 αam1 αam 2 αamn
α = 4,
1 2 4 8 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 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 p
cij = ∑ aik bkj k =1
Example - Matrix Multiplication
a = (a1, a2 ,, an )
b1 b2 b= bn
c1x1 = a1xn bnx1 (scalar)
b1 b2 c = a ⋅ b = (a1, a2 ,, an ) = a1b1 + a2b2 + + an bn bn
Example - Matrix Multiplication a11 a12 a1n a a22 a2n 21 A= a n1 an 2 ann
b1 b2 b= bn
c nx1 = Anxn bnx1
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 A= 2 4
2 1 B= 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 A = 2 1 4 1 4 3
2 1 B = 1 2 2 1
1 2 3 2 1 C 3 x 2 = A3 x3 B3 x 2 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
Example - Matrix Multiplication 3 0 A = 1 1 5 2
4 7 B= 6 8 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
Diagonal Matrix
Tridiagonal Matrix
0 a11 0 0 a22 0 A = 0 0 0 0 0 a11 a12 a21 a22 A = 0 a32 0 0 0 0
0 a23 0
0 0 0 ann 0 0 a54
0 0 0 a45 a55
Identity Matrix
Identity Matrix 1 0 I = 0 0
0
0
1 0
0 1
0
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
Example - Matrix Inverse
AA −1 = I
• Example (2 x 2) matrix a11 a12 A = a a 21 22
A−1 =
a22 − a12 1 a11a22 − a12 a21 − a21 a11
Special Matrices
Upper Triangular Matrix
Lower Trangular Matrix
u11 u12 0 u22 U= 0 0 0 0
u13 u14 u23 u24 u33 u34 0 u44
0 L11 L21 L22 L= L31 L32 L 41 L42
0 0 L33 L43
0 0 0 L44