I n - USC Upstate: Faculty

Download Report

Transcript I n - USC Upstate: Faculty

Introduction to Matrices and
Vectors
Sebastian van Delden
USC Upstate
[email protected]
Introduction
Definition: A matrix is a rectangular array of
numbers.
 a11 a12
a
a22
21

A

 
a
 m1 am 2
 a1n 
 a2 n 

aij
 
 amn 
element in ith row, jth column
m rows
Also written as A=aij
mn matrix
n columns
When m = n, A is called a square matrix.
Matrix Equality

Definition: Let A and B be two matrices. These
matrices are the same, that is, A = B if they
have the same number of rows and columns,
and every element at each position in A equals
the element at corresponding position in B.
* This is not trivial if elements are real numbers
subject to digital approximation.
The Transpose of a Matrix
 x11 x12
x
x22
21
T

X 
 

 xn1 xn 2
 x11 x21
x
x22
  12
 

 x1n x2 n








x1m 
x2 m 
 

xnm 
xm1 
xm 2 
 

xmn 
T
1 2 3
A

4
5
6


1 4 
A T  2 5
3 6
Note that (XT)T = X
14 2 
B

3
14


14 3 
B 

2
14


T
Matrix Addition, Subtraction
Let A = aij , B = bij be mn matrices. Then:
A + B = aij + bij, and A – B = aij – bij
1  1 3 4  4 3
 3 4   1  4    4 0 

 
 

2 0  2 3  4 3
1  1 3 4   2  5
 3 4   1  4    2
8

 
 

2 0  2 3   0  3
5
Properties of Matrix Addition

Commutative:
A+B=B+A

Associative:
A + (B + C) = (A + B) + C
Inventories


Makealot, Inc. manufactures widgets, nerfs,
smores, and flots.
It supplies three different warehouses
(#1,#2,#3).
Opening
inventory:
w
Sales:
n
s
f
#1
#2
20 50 25 10
#3
2
55 12 33 90
45 89
Closing
inventory:
6
–
15
0
25
3
5
50
0
7
35
6
30 10
= 20
6
3
80
2
4
12
41 77
3
3
0
Scalar Multiplication
1

3
10 
5
7

2
10
 
4 30


6 50
8 70
20

40
60
80
Associative:
c1(c2A) = (c1c2)A
Distributive:
(c1 + c2) A = c1A + c2A
Matrix Multiplication
Let A be an mk matrix, and B be a kn
matrix. Then their product is: AB=[cij]
k
cij   ait btj  ai1b1 j  ai 2b2 j 
t 1
 a11
a
 21
a12
a22
a13 
a23 
b11 b12
b
b
 21 22
b31 b32
b13
b23
b33
 aik bkj
b14 
 c11 c12

b24  
 c21 c22
b34 
a11b12  a12b22  a13b32  c12
c13
c23
c14 
c24 
Matrix Multiplication
Let A be an mk matrix, and B be a kn
matrix. Then their product is: AB=[cij]
k
cij   ait btj  ai1b1 j  ai 2b2 j 
t 1
 a11
a
 21
a12
a22
a13 
a23 
b11 b12
b
b
 21 22
b31 b32
b13
b23
b33
 aik bkj
b14 
 c11 c12

b24  
 c21 c22
b34 
a21b12  a22b22  a23b32  c22
c13
c23
c14 
c24 
Matching Dimensions
To multiply two matrices, the dimensions must
match:
23 34
24 matrix
have to be equal
 a11
a
 21
a12
a22
23
a13 
a23 
b11 b12
b
b
 21 22
b31 b32
b13
b23
b33
34
b14 
 c11 c12

b24  
 c21 c22
b34 
c13
c23
24
8 dot products
c14 
c24 
Multiplicative Properties
Note even if AB is defined, BA might not be.
Example: If A is 34, B is 46, then AB is a 36 matrix,
but BA is not defined.
Even if both AB and BA are defined, they may not have
the same dimensions.
Even if they do, the result might
not be equal.
However, provided that the
dimensions match, (AB)C = A(BC)
1 1
2 1
A
B


2
1
1
1




3 2
 4 3
AB  
BA  


5
3
3
2




Chained Matrix Multiplication
What is the most efficient way of carrying out the
following chained matrix multiplication?
M 
135   589   893   334
Chained Matrix Multiplication
What is the most efficient way of carrying out the
following chained matrix multiplication.
M   M 1 135   M 2 589   M 3 893   M 4 334
Let's try:
M   M 1 135  5  89  3  133553   M 4 334
M  13  5  3  195133   M 4 334
M  13  3  34  13261334
Total multiplications = 1335  195  1326  2856.
Chained Matrix Multiplication
What is the most efficient way of carrying out the
following chained matrix multiplication.
M   M 1 135   M 2 589   M 3 893   M 4 334
Answer:


M   M 1 135   M 2 589   M 3 893    M 4 334
This would require 2856 multiplications
Example
What is the most efficient way of carrying out the
following chained matrix multiplication?
M 
95   52   26
Example
What is the most efficient way of carrying out the
following chained matrix multiplication?
M 
95   52   26
Answer:
If we do
    
95
52

26   the cost is
5  2  6  9  5  6  330
If we do
  
95

52    26  the cost is
9  5  2  9  2  6  198. So, this is the optimal way.
Ways of Parenthesizing a product of n matrices


Let T(n) be the number of essentially distinct
ways of parenthesizing a product of n
matrices. The values of T(n) are known as
Catalan numbers. Here are few values of
T(n):
n
1 2 3 4 5 … 10 … 15
T(n) 1 1 2 5 14 … 4862 … 2674440
It can be shown that
T(n) = Ω(22n/n2)
Identity Matrix
The identity matrix is a square matrix with all 1’s along
the diagonal and 0’s elsewhere. Example:
1 0 0
For an mn matrix A, Im A = A In


I3  0 1 0


(mm) (mn) = (mn) (nn)
0 0 1
1 0 0 a
0 1 0   c


0 0 1  e
b  a  0  0 b  0  0 
d   0  c  0 0  d  0 
 

f   0  0  e 0  0  f 
Inverse Matrix

Let A and B be nn matrices.
If AB=BA=In then B is called the inverse of A,
denoted B=A-1.

Not all square matrices are invertible.

Symmetric Matrix
If matrix A is such that A = AT then it is called a
symmetric matrix. For example:
 1 4 1
4 3 0


 1 0 2 
is symmetric. Note, for A to be symmetric, is
has to be square. Note also that In is trivially
symmetric.
Vectors
An m element column vector
a 1 
a 
a 2
 
 
a m 
Transpose the column
aT  [a1
a2  am ].
A q element row vector
b  [b1b2 bq ]
Transpose the row
b1 
b 
2
T
b  

 
bq 
Vectors

A 1xN or Nx1 matrix





1xN is called a row vector
Nx1 is called a column vector
N is the dimension of the vector
Vectors can be drawn as arrows and so have
a direction and a magnitude.
Magnitude:
a12  a22 ...  an2
 a1 
a 
given a   2 
 
 
 an 
Drawing Vectors
y
a = (8,5)
5
8
x
Unit Vectors


Magnitude is 1
A normalized vector is a unit vector that has be obtained by divided
each dimension of a vector by its magnitude.


It has the same direction as the original vector.
Important because something direction is all that is important – magnitude is not
needed…
y
|a| = sqrt(82 + 52) =~ 9.4
Normalized a, a’ = (8/9.4, 5/9.4) = (.85, .53)
5
a = (8,5)
a’ = (.85, .53)
8
x
Geometry of Vectors
If m is magnitude:
a = m . cos 
y
, b = m . sin
For unit vectors:
a = cos 
, b = sin
(a, b)
b

= tan-1(b/a)

a
x
Addition
- preserves direction and magnitude.
- application: robot position translations
- tip to tail method:
y
u+v
u
v
x
Subtraction
- application: can represent robot position error vector
- u – v, a vector originating in v and ending in u
y
u-v
u
v
x
Multiplication with a scalar
- can change magnitude and direction (if multiplied with a
negative number.
y
u
v
½v
x
-u
Cross Product


Produces a vector perpendicular (normal) to
the plane created by the 2 vectors.
uxv
uxv
v
u
Cross product

Direction is determined by the right hand rule



Put hand on first vector (left side of x) and curl
fingers towards second vector.
Magnitude of u x v is |u| . |v| . sin(theta)
where theta is the angle between u and v
So, cross product produces a vector
Dot product




Length of the projection of one vector onto a another.
 u . v
Dot product is |u| . |v| . cos(theta) where theta is the
angle between u and v
So, dot product produces a scalar
Note: is u and v and unit vectors, the dot product is
simply: cos(theta)
u
theta
cos (theta)
v
Dot and cross products


Dot product from unit vectors:
 As angle approaches 0, dot product approaches 1
 As angle approaches 90, dot product approaches 0
Cross product from unit vectors:
 As angle approaches 0, dot product approaches 0
 As angle approaches 90, dot product approaches 1
Finally….



Perpendicular vectors (dot product
= 0) are called orthogonal vectors.
Orthogonal unit vectors are called
orthonormal vectors.
Think: what do you need to
represent a 3D coordinate
system…? Three orthonormal
vectors: X, Y, and Z….