Professional Documents
Culture Documents
ME3209 - Topic 2 - Basics of Matrix and Vector Operations
ME3209 - Topic 2 - Basics of Matrix and Vector Operations
ME3209 - Topic 2 - Basics of Matrix and Vector Operations
1. Basics of Matrices
2. Basics of Vectors
3
OBJECTIVES
What you gain from this lecture:
1. Matrix operations: matrix addition and subtraction,
scalar multiplication of matrices, matrix
multiplication, matrix transpose and inverse.
4
NEXT CONTENT
1. Basics of Matrices
1.1. Matrix Definition
1.2. Matrix Operations
1.3. Matlab codes
2. Basics of Vectors
3. Derivatives of Matrices and Vectors
5
1. BASICS OF MATRICES
1.1. Matrix Definition
▪ Dimension = (m x n ) 1 2
A= ; a12 = 2
3 4
a
▪ Element in i row and j column: ij
th th
1 2 3
▪ Square matrix: m=n (size n) C= ; c22 = 5
1 2 4 5 6
B = 3 4 ; b32 = 6
5 6
6
1. BASICS OF MATRICES
1.1. Matrix Definition
0 0 .. 0 1 0 .. 0
▪ Zero matrix: m=n and aij=0 i, j
0 0 .. 0 0 1 .. 0
A= I=
.. .. .. .. .. ..
▪ Identity matrix: m = n and aij = 0 i ≠ j, 0 0 .. 0
0 0 .. 1
and aij = 1 otherwise
u11 u12 .. u1n
0 u22 .. u 2n
▪ Upper triangular matrix: m=n, aij=0 i > j U=
... ... ...
l11 0
0 0 0 0 0 unn
l21 l22 0 0
L=
▪ Lower triangular matrix: m=n, aij=0 i < j .. .. 0
ln 1 ln 2 .. lnn
7
1. BASICS OF MATRICES
1.1. Matrix Definition
a11 0 .. 0
▪ Diagonal matrix: m=n and aij=0 i ≠ j
0 a22 .. 0
A=
.. .. .. ..
0 0 .. ann
a a12 .. a1n
11
▪ Symmetric matrix: m=n, aij=aji i ≠ j
a12 a22 .. a2n
A=
... ... ..
a1n a2n ... ann
0 a12 .. a1n
▪ Skew symmetric matrix: m = n, aij = -aji i ,
−a12 0 .. a2n
A=
j ... ... ..
−a1n −a2n ... 0
8
1. BASICS OF MATRICES
1.1. Matrix Definition
▪ Block matrix:
a a12 a a14
a11 a12 a13 a14 11 13
A11 = a21 a22 , A12 = a23 a24
a21 a 22 a 23 a 24 A11 A12
A= = a a 32 a a 34
a a 32 a 33 a 34 A A22 31 33
31 21
a 41 a 42 a 43 a 44
A21 = a 41 a 42 , A22 = a 43 a 44
0, i j
A = [a1,a 2 ,..., a n ] : ai a j =
T
1, i = j
9
1. BASICS OF MATRICES
1.2. Matrix Operations
▪ Addition and Subtraction: all matrices must be of the same dimension
C = A B, cij = aij bij , i = 1, 2,..., m; j = 1, 2,..., n
C = A + B = B + A; C = A − B = −(B − A)
▪ Scalar Multiplication of Matrices: A = [aij ] A = [aij ]
▪ Matrix Transpose:
a11 a12 .. a1n a11 a21 .. am 1
a21 a22 .. a 2n a12 a22 .. am 2
A= A =
T
.. .. .. .. .. ..
am 1 am 2 .. amn
a1n a2n .. amn
10
1. BASICS OF MATRICES
1.2. Matrix Operations
▪ Matrix Multiplication:
p
Cm n = Am p Bp n , cij = a
k =1
b ,
ik kj
i = 1, 2,..., m; j = 1, 2,..., n
(ABC)T = CT BT AT AB BA
a1 a2 b1 b2
A= ; B =
a
3 a 4
b b
3 4
(a1b1 + a2b3 ) (a1b2 + a 2b4 ) (a1b1 + a 3b2 ) (a 2b1 + a 4b2 )
AB = ; BA =
(a b
3 1 + a b ) (a b + a b )
4 4
(a b
1 3 + a b ) (a b + a b )
4 4
4 3 3 2 3 4 2 3
11
1. BASICS OF MATRICES
1.2. Matrix Operations
▪ Matrix Determinant: for square matrix only, using Laplace expansion ( not the
only method)
a11 a12 a11 a12
A= , det(A) = A = = a11a22 − a21a12
a21 a22
a21 a22
a a12 a13
11
A = a21 a22 a23 ,
a a a
31 32 33
12
1. BASICS OF MATRICES
1.2. Matrix Operations
▪ Matrix Determinant: for square matrix only, using Laplace expansion ( not the
only method)
a11 a12 .. a1n a11 a12 .. a1n
a 21 a 22 .. a 2n a 21 a 22 .. a 2n
A= , dn = det(A) =
.. .. .. .. .. ..
an 1 an 2 .. ann
an 1 an 2 .. ann
n n
dn = A = (−1) aik M ik =
i =1
i +k
aik Aik ;
i =1
Aik = (−1)i +k M ik 𝑀𝑖𝑘 the minor of the
element 𝑎𝑖𝑘
13
1. BASICS OF MATRICES
1.2. Matrix Operations
▪ Matrix Inverse: for square matrix only, A => A-1, AA-1 = A-1A = I
− Step 1: calculating the Matrix of Minors,
− Step 2: then turn that into the Matrix of Cofactors,
− Step 3: then the Adjugate, and
− Step 4: multiply that by 1/Determinant.
3 0 2 2 2 0 0.2 0.2 0
1
A = 2 0 −2 A −1 = −2 3 10 = −0.2 0.3 1
0 1 1 10
2 −3 0 0.2 −0.3 0
14
1. BASICS OF MATRICES
1.2. Matrix Operations
▪ Matrix Inverse: for square
matrix only,
A=> A-1, AA-1 = A-1A = I
− Step 1: calculating the Matrix of
Minors,
• For each element of the matrix:
• ignore the values on the current
row and column
• Calculate the determinant of the
remaining values
• Put those determinants into a
matrix (the "Matrix of Minors")
18
1. BASICS OF MATRICES
1.3. Matlab Codes
19
NEXT CONTENT
1. Basics of Matrices
2. Basics of Vectors
2.1. Vector Definition
2.2. Vector Operations
2.3. Matlab Codes
3. Derivatives of Matrices and Vectors
20
2. BASICS OF VECTORS
2.1. Vector Definition
▪ Geometric vectors:
− Representation: graphically as directed line segments with both a B
magnitude (length) and direction.
− Notation: a = AB
A
− Magnitude: a = a = AB = AB
▪ Unit vectors: a
− Notation: e , i , j , k
− Magnitude: e = i = j = k = 1 e
− Used to represent other vectors: a = ae
a
21
2. BASICS OF VECTORS
2.1. Vector Definition
▪ Algebraic vectors:
− Representation: as ordered sets of numbers (components) z
− Magnitude: a = a x + ay + a z
2 2 2 x
y x y
i , j ,k
− Relationship between a geometric vector and an algebraic
vector
a ax i ay j az k a1e1 a 2e2 a 3e3
22
2. BASICS OF VECTORS
2.1. Vector Definition
▪ Cosine direction of a vector:
z0
ax e10 a a
cos = = e 3o
a a cos = e 0 a
ay e20 a 1
23
2. BASICS OF VECTORS
2.2. Vector Operations
▪ Addition and Subtraction:
b
a [ax ay az ]T , b [bx by bz ]T
c a b
a c a c a b [ax bx ay by az bz ]T
c
d a b
a ( b) a c d a b [ax bx ay by az bz ]T
d
b
b
24
2. BASICS OF VECTORS
2.2. Vector Operations
▪ Scalar multiplication:
b a, a [ax ay az ]T ,
b
b a [ ax ay az ]T
a b
a
▪ Dot product:
a b | a || b | cos(a , b ) b a a
a [ax ay az ]T , b [bx by bz ]T
| a || b | cos b aT b bT a [axbx ayby azbz ]T
25
2. BASICS OF VECTORS
2.2. Vector Operations
▪ Cross product: c
b
c a,c b
c a b right handed rule
a
| c | | a || b | sin a ax i ay j az k ,
a b c 0, b bx i by j bz k ,
c cx i cy j cz k z ,
c a b b a
i j k
c a b Area of the parallelogram c a b ax ay az
formed by the two vectors. bx by bz
26
2. BASICS OF VECTORS
2.2. Vector Operations
▪ Cross product:
T 0 az ay
a [ax ay az ]
T a az 0 ax S (a ) Skew(a )
b [bx by bz ]
T ay ax 0
c [cx cy cz ]
cx 0 az ay bx
cy az 0 ax by , c a b b a, c ab ba
cz ay ax 0 bz l a (b c) l a(bc ) abc
(a c )b (a b )c (aT c )b (aT b )c
c ab
27
2. BASICS OF VECTORS
2.3. Matlab Codes
28
NEXT CONTENT
1. Basics of Matrices
2. Basics of Vectors
3. Derivatives of Matrices and Vectors
3.1. Time Derivatives of Matrices and Vectors
3.2. Scalar-to-Vector Derivatives
3.3. Vector-to-Vector Derivatives
3.4. Matlab Codes
29
3. DERIVATIVES OF MATRICES AND VECTORS
3.1. Time Derivatives of Matrices and Vectors
▪ Time Derivatives of Vectors: % Define symbolic variables and
vectors
syms t real;
da
a [a1, a2 ,..., an ]T % Define vector
dt a = [t^2; sin(t)];
30
3. DERIVATIVES OF MATRICES AND VECTORS
3.1. Time Derivatives of Matrices and Vectors
▪ Time Derivatives of Matrices: % Define symbolic variables and
vectors
dA syms t real;
A {aij }
dt % Define a time-dependent matrix
A = [t^2 t; sin(t) cos(t)];
d d % dA/dt
( A) A A, (A B) A B dA_dt = diff(A, t);
dt dt
d d % Display the result
(AB) AB AB, (Ab) Ab Ab disp('Derivative of A with respect to
dt dt t:');
disp(dA_dt );
1
AA E d
dt
(AA 1 ) AA 1
A dtd (A 1 ) 0 d
dt
(A 1 ) A 1AA 1
31
3. DERIVATIVES OF MATRICES AND VECTORS
3.2. Scalar-to-Vector Derivatives % Define symbolic variables and
vectors
q n 1, a = a(q) syms x y real;
a(q) a a
a = x^2 + sin(y);
a
= ...
q = [x; y];
q q1 q 2 qn % Compute the derivative of a wrt
vector q
da_dt = jacobian(a, q);
▪ Gradient of a scalar function:
% Display the result
n 1
f = f (x) , x f (x) disp('Derivative of a with respect to
q:');
x 1
disp(da_dq );
T
f (x)
f (x) = =
x
f (x)
x n
32
3. DERIVATIVES OF MATRICES AND VECTORS
3.3. Vector-to-Vector Derivatives
33
3. DERIVATIVES OF MATRICES AND VECTORS
3.3. Vector-to-Vector Derivatives
▪ Hessian Matrix: a symmetric matrix in the form
H f (x) = [f (x)] = Jacobian[f (x)]
2 f (x) 2 f (x) 2 f (x) x
x 1x 1 x 1x 2 x 1x n
2 f (x) 2 f (x) 2 f (x) 2 f (x)
f (x)
T
[H f (x)]ij =
H f (x) = = x 2 x 1 x 2 x 2 x 2 x n x i x j
x x
2
f (x) 2 f (x) 2 f (x)
x x x n x 2 x n x n
n 1
34
3. DERIVATIVES OF MATRICES AND VECTORS
3.4. Matlab Codes
% Define the vector with respect to which you want to take the
▪ Vector-to-Vector Derivatives derivative
q = [x; y; z];
35
CONCLUSIONS
THANK YOU
and
QUESTIONS
38