Computations in Mechanical Engineering: Matrices
Computations in Mechanical Engineering: Matrices
Third Edition
Tradition & Excellence Since 1821 Mechanical Engineering
TOPIC
ME 354
03 Computations in
Mechanical Engineering
Matrices
What is a MATRIX ?
is
Matrix
The
03 - 2
Matrices: Definition
Definition • A matrix is a rectangular array of elements written as
An m n matrix
A matrix of size m n
A matrix of order m n
Sometimes A is denoted as A = [aij] or (aij)
03 - 3
Matrices Operations: Addition & Scalar Multiplication
Addition • Two matrices of the same size can be added by performing
element-by-element addition, i.e.,
a11 a12 a1n b11 b12 b1n
a a2 n b b2n
21 a22
b22
A B 21
a amn b
m1 am 2 m1 bm 2 bmn
Notes A T T
A
( AB )T BT AT
• A+B=B+A
• (A + B) + C = A + (B + C)
• A(B + C) = AB + AC
• (A + B)C = AC + BC
• k(A + B) = kA + kB
• A(BC) = (AB)C
• (AB)T = BTAT
03 - 7
Matrix Operations: MATLAB© Commands
Types Operation Command Math Form
Basic Addition (subs) AB AB
Operations Scalar Multipl. k*A kA
Transpose A’ AT or A’
Multiplication A*B AB
Matrix Single Element A(i,j) aij
Index
Row A(i,:) [ai1, ai2, …, ain]
Column A(:,j) [a1j, a2j, …, amj]T
Sub-matrix A(i:j,k:l) A sub-matrix of A from rows i to
j and from columns k to l
Define Empty matrix [] Empty matrix
Special Matrix of 1s ones(m,n) m n matrix of ones
Matrices
Matrix of 0s zeros(m,n) m n matrix of zeros
Matrix of random rand(m,n) m n matrix of random
numbers numbers
03 - 8
MATLAB© Element-by-Element Operations
Operation Command Math Form
Multiplication A.*B a11b11 a1nb1n
am1bm1 amnbmn
Power A.^k a11k
a1kn
a k k
amn
m1
Function f(A) f (a11 ) f (a1n )
f (am1 ) f (amn )
Add Scalar A+k a11 k a1n k
am1 k amn k
>> eye(n)
03 - 11
Determinants
Definition • The determinant of a square matrix A (n n) is a number, denoted
as det(A) or |A|.
How to • The determinant can be computed using the Laplace expansion.
Compute? To do that, the minor and the cofactor need to be defined.
Minor The minor of the element aij designated Mij is the n–1 n –1
submatrix of A by deleting row i and column j. For example
a11 a12 a1n a21 a23 a3n
a a22 a2n a a33 a3n
A 21 M12 31
a a
n1 a n2 a nn n1 a n3 a nn
Cofactor The cofactor of aij, designated Aij is value (–1)i+j det(Mij).
Laplace Exp • The determinant of A can be determined using all elements and
their cofactors of a row OR a column as follows:
n n
k j
Expand by
detA akj Akj 1 akj det M kj
Row k j 1 j 1
n n
ik
detA aik Aik 1 aik detM ik
Expand by
Column k
03 - 12 i 1 i 1
Determinants of Order 2 and 3: Expand by 1st Row
a a
• A 2nd order matrix A 11 12
a21 a22
03 - 14
• >> det(A)
Square Matrices: Inverse
Reciprocal • For a number a 0, aa–1 = a–1a = 1, a–1 is the inverse of a.
Inverse • Inverse of a square matrix A, designated A–1 is such that
Matrix AA–1 =A–1A = I
The inverse A–1 may not exist.
If the inverse A–1 exists, A is said to be invertible or
nonsingular. Otherwise, A is noninvertible or more
commonly singular.
If A is invertible, then det(A) 0, vice versa.
Only a square matrix can have an inverse.
I–1 = I
(AB)–1 = B–1 A–1
How? • Using cofactors.
• Solve for each element in A–1 from AA–1 = I
• Using elementary row operations.
• >>inv(A), >>rref(A)
03 - 15
• …
Inverse Matrix: Using cofactors
Cofactors • Recall the cofactor Aij
The minor of the element aij designated Mij is the n–1 n –1
submatrix of A by deleting row i and column j. For example
a11 a12 a1n a21 a23 a3n
a a2 n a a33 a3n
21 a22
A M12 31
a ann a
n1 an 2 n1 an3 ann
Aij = (–1)i+j det(Mij).
Inverse T
A11 A12 A1n
Matrix A A22 A2n
1 adjA 21
1
• A adjA
detA
A
n1 An 2 Ann
1 1 2 0 1 0 1 1 2 0 1 0
3 –3R1 + R2 0 4 6 1 3 0 R2 R3
1 0 1 0 0
0 2 4 0 0 1 0 2 4 0 0 1
1 1 2 0 1 0 1 1 2 0 1 0 –R + R
0 2 0 1 2 0 0 1 / 2 2 1
4 0 0 1 1/2 R2 4R2 + R3
0 4 6 1 3 0 0 4 6 1 3 0
1 0 0 0 1 1 / 2 1 0 0 0 1 1 / 2
0 1 2 0 0 1 / 2 1/2 R3 0 1 2 0 0 1 / 2 –R3 + R2
0 0 2 1 3 2 0 0 1 1 / 2 3 / 2 1
1 0 0 0 1 1/ 2 0 1 1/ 2
0 1 0 1 3 3 / 2 A 1 1 3 3 / 2 See Ex03_02.m.
0 0 1 1 / 2 3 / 2 1 1 / 2 3 / 2 1
03 - 18
Square Matrices: Orthogonal Matrices
Orthogonal • An orthogonal matrix Q is an n n matrix that is invertible and
Matrices Q–1 = QT or QTQ = QQT = I
1 0 0
l 1 0
• A unit lower triangular
L 21 matrix with all diagonal
elements equal to 1
l 1
n1 ln 2
03 - 21
LU Factorization: Equations
Manual a11 a12 a1n 1 0 0 u11 u12 u1n
a a22 a2n l21 1 0 0 u22 u2n
A 21
a ann ln1
n1 an 2 ln2 1 0 0 unn
How to Get • (1st row of L) (All columns of U) 1st row of U, u1j = a1j
lij and uij?
• (2nd row of L) (All columns of U) 2nd rows of L and U:
l21 a21 / u11, u2 j a2 j l21u1 j
See Ex03_03.m
03 - 23