ME3209 - Topic 2 - Basics of Matrix and Vector Operations

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 36

My Profile

▪ Full name: Dr. Tran Van Quoc

▪ Engineering degree in mechatronics (talent program,


HUST in 2013)

▪ PhD graduation: Gwangju Institute of Science and


Technology, Korea in 2021, Posdoc. at KAIST, Korea
2021-2022.

▪ Workplace: M701 C7, Mechatronics Department,


School of Mechanical Engineering, HUST, Vietnam
Google scholar citations: 330+ ▪ Research Interests: Multi-robot systems, Robotics,
SCIE journal publication: 15
Associate Editor of IJCAS (SCIE Q2)
Automation and Control, etc.
ROBOTICS
Topic 2: Basics of Matrix and Vector Operations
CONTENT

1. Basics of Matrices

2. Basics of Vectors

3. Derivatives of Matrices and 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.

2. Vector operations: vector addition, subtraction,


scalar multiplication, dot product, cross product.

3. Derivatives of matrix and vector over time and a


vector.

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

▪ Usually in bold capitals: A  a11 a12 .. a1n 


 
 a21 a22 .. a 2n 
▪ Number of rows: m A=
.. .. .. 
 
▪ Number of columns: n am 1 am 2 .. amn 

▪ 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 
   

▪ Orthogonal matrix: A = [a1,a 2 ,..., a n ] : aTi a j = 0, i  j


▪ Orthonormal matrix: AAT = I = AA −1  A −1 = AT

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 

a22 a23 a21 a23 a21 a22


det(A) = a11 − a12 + a13
a 32 a 33 a 31 a 33 a 31 a 32

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 𝑎𝑖𝑘

det(A) = det(AT ) det(I) = 1

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")

Image source: https://www.mathsisfun.com/algebra/matrix-inverse-minors-cofactors-adjugate.html 15


1. BASICS OF MATRICES
1.2. Matrix Operations
▪ Matrix Inverse: for square matrix only, A=> A-1, AA-1 =A-1A=I
− Step 2: Matrix of Cofactors,

− Step 3: Adjugate (Adjoint),

Image source: https://www.mathsisfun.com/algebra/matrix-inverse-minors-cofactors-adjugate.html 16


1. BASICS OF MATRICES
1.2. Matrix Operations
▪ Matrix Inverse: for square matrix only, A=> A-1, AA-1 =A-1A=I
− Step 4: Multiply by 1/Determinant

Image source: https://www.mathsisfun.com/algebra/matrix-inverse-minors-cofactors-adjugate.html 17


1. BASICS OF MATRICES
1.3. Matlab Codes

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

within a specific coordinate system


T a
− Notation: a = ax ay az  k
 
z j
i A

− 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

cos  = = | a |= 1  cos  = e20  a  


a a  cos  = e 0  a
az e30  a  3 e1o e o y0
cos  = = x0 2
a a

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)];

% Compute the derivative of a wrt


d time
(a b) a b da_dt = diff(a, t);
dt a, b 3
:
% Display the result
d
( a) a a d disp('Derivative of a with respect to
dt (ab) ab ab, t:');
dt disp(da_dt );
d T
(a b) aT b aT b a a
dt

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;

% Define a scalar and a vector

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

q  n 1, a = a(q)  m 1 a(q)  a a a 


= ... 
q  q1 q 2 qn 
 a a1 a1 
 1 .. 
 q1 q 2 qn 
▪ Jacobian Matrix a(q) 
J= = ... .. .. ..  , J(q)  m n
q  
 am am
..
am 
 q q 2 qn 
 1

▪ Note: (aT )  a1 a1 a a2 a2 a am am  1mn


= , ,..., 1 , ,..., 2 .. ,...,  =: J  R
q  q1 q2 qn q1 q2 qn q1 qn 

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 1x 1 x 1x 2 x 1x 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 symbolic variables and vectors


syms x y z;

% Define the vector-valued function F as an example


a = [x^2*y; sin(z); x*y*z];

% Define the vector with respect to which you want to take the
▪ Vector-to-Vector Derivatives derivative
q = [x; y; z];

% Compute the derivative of a with respect to q


da_dq = jacobian(a, q);

% Display the result


disp('Derivative of vector a with respect to q:');
disp(da_dq);

35
CONCLUSIONS

THANK YOU
and
QUESTIONS

38

You might also like