introduction to matrices and vectors sebastian van delden usc upstate [email protected]

34
Introduction to Matrices and Vectors Sebastian van Delden USC Upstate [email protected]

Upload: norman-dickerson

Post on 03-Jan-2016

225 views

Category:

Documents


0 download

TRANSCRIPT

Introduction to Matrices and Vectors

Sebastian van Delden

USC Upstate

[email protected]

Introduction

mnmm

ij

n

n

aaa

a

aaa

aaa

A

21

22221

11211

m rows

n columns

mn matrix

element in ith row, jth column

When m = n, A is called a square matrix.

Also written as A=aij

Definition: A matrix is a rectangular array of numbers.

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

mnnn

m

m

T

nmnn

m

m

T

xxx

xxx

xxx

xxx

xxx

xxx

21

22212

12111

21

22221

11211

X

63

52

41

654

321

TA

A

142

314

143

214

TB

B

Note that (XT)T = X

5

Matrix Addition, SubtractionLet A = aij , B = bij be mn matrices. Then:A + B = aij + bij, and A –– B = aij –– bij

34

04

34

32

41

43

02

43

11

30

82

52

32

41

43

02

43

11

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:

20

50

25

10

55

12

33

90

245

89

6

15

025

3

35

630

10

2 412

3

550

0 7

20

6 380

041

77

3

Sales: Closing inventory:

– =

w n s f

#1

#2

#3

Scalar Multiplication

8070

6050

4030

2010

87

65

43

21

10

Associative: c1(c2A) = (c1c2)A

Distributive: (c1 + c2) A = c1A + c2A

Matrix MultiplicationLet A be an mk matrix, and B be a kn matrix. Then their product is: AB=[cij]

1 1 2 21

k

ij it tj i j i j ik kjt

c a b a b a b a b

24232221

14131211

34333231

24232221

14131211

232221

131211

cccc

cccc

bbbb

bbbb

bbbb

aaa

aaa

12321322121211 cbababa

Matrix MultiplicationLet A be an mk matrix, and B be a kn matrix. Then their product is: AB=[cij]

1 1 2 21

k

ij it tj i j i j ik kjt

c a b a b a b a b

24232221

14131211

34333231

24232221

14131211

232221

131211

cccc

cccc

bbbb

bbbb

bbbb

aaa

aaa

322212 cbababa 21 22 23 22

Matching Dimensions

24232221

14131211

34333231

24232221

14131211

232221

131211

cccc

cccc

bbbb

bbbb

bbbb

aaa

aaa

To multiply two matrices, the dimensions must match:

23 34

have to be equal

24 matrix

23 34 24

8 dot products

Multiplicative PropertiesNote even if AB is defined, BA might not be.Example: If A is 34, B is 46, then AB is a 36 matrix, but BA is not defined.Even if both AB and BA are defined, they may not havethe same dimensions. Even if they do, the result might not be equal.

23

34

35

23

11

12

12

11

BAAB

BAHowever, provided that the dimensions match, (AB)C = A(BC)

Chained Matrix Multiplication

13 5 5 89 89 3 3 34

What is the most efficient way of carrying out the

following chained matrix multiplication?

M

Chained Matrix Multiplication

1 2 3 413 5 5 89 89 3 3 34

What is the most efficient way of carrying out the

following chained matrix multiplication.

M M M M M

1 413 5 5 3 3 34

413 3 3 34

13 34

Let's try:

5 89 3 1335

13 5 3 195

13 3 34 1326

Total multiplications = 1335 195 1326 2856.

M M M

M M

M

Chained Matrix Multiplication

1 2 3 413 5 5 89 89 3 3 34

What is the most efficient way of carrying out the

following chained matrix multiplication.

M M M M M

1 2 3 413 5 5 89 89 3 3 34

Answer:

This would require 2856 multiplications

M M M M M

Example

9 5 5 2 2 6

What is the most efficient way of carrying out the

following chained matrix multiplication?

M

Example

9 5 5 2 2 6

9 5 5 2 2 6

9 5 5 2 2 6

What is the most efficient way of carrying out the

following chained matrix multiplication?

:

If we do the cost is

5 2 6 9 5 6 330

If we do the cost is

9 5

Answe

2 9 2

r

M

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

100

010

001

3I

The identity matrix is a square matrix with all 1’s alongthe diagonal and 0’s elsewhere. Example:

fe

dc

ba

fe

dc

ba

0000

0000

0000

100

010

001

For an mn matrix A, Im A = A In

(mm) (mn) = (mn) (nn)

Inverse Matrix

Let A and B be nn 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 thatNote also that I Inn is trivially symmetric.

Vectors

m

2

1

a

a

a

a ]bbb[

q21b

An m element column vector A q element row vector

Transpose the column Transpose the row

].[ 21 mT aaaa

q

T

b

b

b

b

2

1

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:

222

21 ... naaa

na

a

a

given

2

1

a

Drawing Vectors

x

y

a = (8,5)

8

5

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…

x

a = (8,5)

8

5

y |a| = sqrt(82 + 52) =~ 9.4Normalized a, a’ = (8/9.4, 5/9.4) = (.85, .53)

a’ = (.85, .53)

Geometry of Vectors

x

y

(a, b)

a

b

If m is magnitude:

a = m . cos , b = m . sin

For unit vectors:

a = cos , b = sin

= tan-1(b/a)

Addition- preserves direction and magnitude.- application: robot position translations- tip to tail method:

x

y

v

u

u + v

Subtraction- application: can represent robot position error vector

- u – v, a vector originating in v and ending in u

x

y

v

uu - v

Multiplication with a scalar- can change magnitude and direction (if multiplied with a negative number.

x

y

v

u

½ v

-u

Cross Product

Produces a vector perpendicular (normal) to the plane created by the 2 vectors.

u x v

v

u

u x v

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

v

cos (theta)

theta

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….