review of linear algebra -...

29
Review of Linear Algebra Dr. Gerhard Roth COMP 4102A Winter 2014 Version 1

Upload: others

Post on 15-Oct-2019

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Review of Linear Algebra - people.scs.carleton.capeople.scs.carleton.ca/~roth/comp4102a-14/notes/lect2_linear_algebra...Ax b. Matrix A matrix is an m ... Example: » » » ¼ º «

Review of Linear Algebra

Dr. Gerhard Roth

COMP 4102A

Winter 2014

Version 1

Page 2: Review of Linear Algebra - people.scs.carleton.capeople.scs.carleton.ca/~roth/comp4102a-14/notes/lect2_linear_algebra...Ax b. Matrix A matrix is an m ... Example: » » » ¼ º «

Linear algebra

• Is an important area of mathematics

• It is the basis of computer vision

• Is very widely taught, and there are many

resources and books available

• We only focus on the basics

• Need to understand matrices, vectors and

their basic operations

Page 3: Review of Linear Algebra - people.scs.carleton.capeople.scs.carleton.ca/~roth/comp4102a-14/notes/lect2_linear_algebra...Ax b. Matrix A matrix is an m ... Example: » » » ¼ º «

Linear Equations

A system of linear equations, e.g.

1114

242

21

21

xx

xx

can be written in matrix form, m rows and n columns:

1

2

114

42

2

1

x

x

or in general:

bAx

Page 4: Review of Linear Algebra - people.scs.carleton.capeople.scs.carleton.ca/~roth/comp4102a-14/notes/lect2_linear_algebra...Ax b. Matrix A matrix is an m ... Example: » » » ¼ º «

Matrix

A matrix is an m×n array of numbers.

ij

mnmm

n

n

a

aaa

aaa

aaa

A

21

22221

11211

Example:

111070

9314

4532

A

Page 5: Review of Linear Algebra - people.scs.carleton.capeople.scs.carleton.ca/~roth/comp4102a-14/notes/lect2_linear_algebra...Ax b. Matrix A matrix is an m ... Example: » » » ¼ º «

Matrix Arithmetic

Matrix addition

nmijijnmnm baBA

Matrix multiplication

pmpnnm CBA

n

k

kjikij bac1

Matrix transpose

ji

T aA

TTTBABA TTT

ABAB

Page 6: Review of Linear Algebra - people.scs.carleton.capeople.scs.carleton.ca/~roth/comp4102a-14/notes/lect2_linear_algebra...Ax b. Matrix A matrix is an m ... Example: » » » ¼ º «

Multiplication not commutative

BAAB

Matrix multiplication is not commutative

Example:

1119

2917

51

26

13

52

1017

3218

13

52

51

26

Page 7: Review of Linear Algebra - people.scs.carleton.capeople.scs.carleton.ca/~roth/comp4102a-14/notes/lect2_linear_algebra...Ax b. Matrix A matrix is an m ... Example: » » » ¼ º «

Symmetric Matrix

We say matrix A is symmetric if

AAT

Example:

54

42A

A symmetric matrix has to be a square matrix

Page 8: Review of Linear Algebra - people.scs.carleton.capeople.scs.carleton.ca/~roth/comp4102a-14/notes/lect2_linear_algebra...Ax b. Matrix A matrix is an m ... Example: » » » ¼ º «

Inverse of matrix

If A is a square matrix, the inverse of A, written A-1 satisfies:

IAA 1 IAA 1

Where I, the identity matrix, is a diagonal matrix with all 1’s

on the diagonal.

10

012I

100

010

001

3I

Page 9: Review of Linear Algebra - people.scs.carleton.capeople.scs.carleton.ca/~roth/comp4102a-14/notes/lect2_linear_algebra...Ax b. Matrix A matrix is an m ... Example: » » » ¼ º «

Vectors – matrices with one column

nx

x

x

x2

1

5

3

2

xe.g.

The length or the norm of a vector is

22

2

2

1 nxxxx

38532 222 xe.g.

A vector is an n by 1 matrix, it is a column in our book

Page 10: Review of Linear Algebra - people.scs.carleton.capeople.scs.carleton.ca/~roth/comp4102a-14/notes/lect2_linear_algebra...Ax b. Matrix A matrix is an m ... Example: » » » ¼ º «

Vector Arithmetic

22

11

2

1

2

1

vu

vu

v

v

u

uvu

22

11

2

1

2

1

vu

vu

v

v

u

uvu

Vector addition

Vector subtraction

Multiplication by scalar

2

1

2

1

u

u

u

uu

Page 11: Review of Linear Algebra - people.scs.carleton.capeople.scs.carleton.ca/~roth/comp4102a-14/notes/lect2_linear_algebra...Ax b. Matrix A matrix is an m ... Example: » » » ¼ º «

Dot Product (inner product)

5

3

2

a

2

3

4

b

925)3(342

2

3

4

532

baba T

nn

T bababababa 2211

Page 12: Review of Linear Algebra - people.scs.carleton.capeople.scs.carleton.ca/~roth/comp4102a-14/notes/lect2_linear_algebra...Ax b. Matrix A matrix is an m ... Example: » » » ¼ º «

Vectors: Dot Product (Inner product)

T

d

A B A B a b c e ad be cf

f

2 TA A A aa bb cc

)cos(BABA

Think of the dot product as

a matrix multiplication

The magnitude is the dot

product of a vector with itself

The dot product is also related to the

angle between the two vectors

Page 13: Review of Linear Algebra - people.scs.carleton.capeople.scs.carleton.ca/~roth/comp4102a-14/notes/lect2_linear_algebra...Ax b. Matrix A matrix is an m ... Example: » » » ¼ º «

Trace of Matrix

The trace of a matrix:

n

i

iiaATr1

)(

Page 14: Review of Linear Algebra - people.scs.carleton.capeople.scs.carleton.ca/~roth/comp4102a-14/notes/lect2_linear_algebra...Ax b. Matrix A matrix is an m ... Example: » » » ¼ º «

Orthogonal Matrix

A matrix A is orthogonal if

IAAT 1 AATor

Example:

cossin

sincosA

Page 15: Review of Linear Algebra - people.scs.carleton.capeople.scs.carleton.ca/~roth/comp4102a-14/notes/lect2_linear_algebra...Ax b. Matrix A matrix is an m ... Example: » » » ¼ º «

Matrix Transformation (and projections)

A matrix-vector multiplication transforms one vector to another

11 mnnm bxA

26

16

41

7

3

24

13

52

Example:

Page 16: Review of Linear Algebra - people.scs.carleton.capeople.scs.carleton.ca/~roth/comp4102a-14/notes/lect2_linear_algebra...Ax b. Matrix A matrix is an m ... Example: » » » ¼ º «

Coordinate Rotation

y

x

y

x

r

r

r

r

cossin

sincos

'

'

Page 17: Review of Linear Algebra - people.scs.carleton.capeople.scs.carleton.ca/~roth/comp4102a-14/notes/lect2_linear_algebra...Ax b. Matrix A matrix is an m ... Example: » » » ¼ º «

Vectors and Points

Two points in a Cartesian coordinate system define a vector

P(x1,y1)

Q(x2,y2)

x

y v

12

12

yy

xxv

P(x1,y1)

Q(x2,y2)

x

y v

A point can also be represented as a vector, defined by the point

and the origin (0,0).

PQv

1

1

1

1

0

0

y

x

y

xP

2

2

2

2

0

0

y

x

y

xQ

or vPQ

Note: point and vector are different; vectors do not have positions

Page 18: Review of Linear Algebra - people.scs.carleton.capeople.scs.carleton.ca/~roth/comp4102a-14/notes/lect2_linear_algebra...Ax b. Matrix A matrix is an m ... Example: » » » ¼ º «

Least Squares

When m>n for an m-by-n matrix A, bAx has no solution.

In this case, we look for an approximate solution.

We look for vector such that x

2bAx

is as small as possible.

This is called the least squares solution.

Page 19: Review of Linear Algebra - people.scs.carleton.capeople.scs.carleton.ca/~roth/comp4102a-14/notes/lect2_linear_algebra...Ax b. Matrix A matrix is an m ... Example: » » » ¼ º «

Least Squares

Least squares solution of linear system of equations

bAx

bAAxA TT

AAT is square and symmetric

bAAAx TT 1)(

Normal equation:

2bxA

The Least Square solution

makes minimal.

Page 20: Review of Linear Algebra - people.scs.carleton.capeople.scs.carleton.ca/~roth/comp4102a-14/notes/lect2_linear_algebra...Ax b. Matrix A matrix is an m ... Example: » » » ¼ º «

Least Square Fitting of a Line

x

y

mm ydxc

ydxc

ydxc

22

11

mm y

y

y

d

c

x

x

x

2

1

2

1

1

1

1

The best solution c, d is the one that minimizes:

.)()( 22

11

22

mm dxcydxcyAxyE

Line equations:

yAx

Page 21: Review of Linear Algebra - people.scs.carleton.capeople.scs.carleton.ca/~roth/comp4102a-14/notes/lect2_linear_algebra...Ax b. Matrix A matrix is an m ... Example: » » » ¼ º «

Least Square Fitting - Example

x

y

P1=(-1,1), P2=(1,1), P3=(2,3)

Problem: find the line that best fit these three points:

Solution:

32

1

1

dc

dc

dc

3

1

1

21

11

11

d

c

bAAxA TT

6

5

62

23

d

c

or

is

The solution is and best line is 74

79 , dc yx 7

479

Page 22: Review of Linear Algebra - people.scs.carleton.capeople.scs.carleton.ca/~roth/comp4102a-14/notes/lect2_linear_algebra...Ax b. Matrix A matrix is an m ... Example: » » » ¼ º «

Homogeneous System

• m linear equations with n unknowns Ax = 0

• Assume that m >= n-1 and rank(A) = n-1

• Trivial solution is x = 0 but there are more

• If we have a given solution x, s.t. Ax = 0 then

c * x is also a solution since A(c* x) = 0

• Need to add a constraint on x, • Usually make x a unit vector

• Can prove that the solution of Ax = 0

satisfying this constraint is the eigenvector

corresponding to the only zero eigenvalue of

that matrix

1 x xT

AAT

Page 23: Review of Linear Algebra - people.scs.carleton.capeople.scs.carleton.ca/~roth/comp4102a-14/notes/lect2_linear_algebra...Ax b. Matrix A matrix is an m ... Example: » » » ¼ º «

Homogeneous System

• This solution can be computed using the

eigenvector or SVD routine • Find the zero eigenvalue (or the eigenvalue almost zero)

• Then the associated eigenvector is the solution x

• And any scalar times x is also a solution

Page 24: Review of Linear Algebra - people.scs.carleton.capeople.scs.carleton.ca/~roth/comp4102a-14/notes/lect2_linear_algebra...Ax b. Matrix A matrix is an m ... Example: » » » ¼ º «

Linear Independence

• A set of vectors is linear dependant if one of

the vectors can be expressed as a linear

combination of the other vectors.

• A set of vectors is linearly independent if

none of the vectors can be expressed as a

linear combination of the other vectors.

nnkkkkk vvvvv 111111

Page 25: Review of Linear Algebra - people.scs.carleton.capeople.scs.carleton.ca/~roth/comp4102a-14/notes/lect2_linear_algebra...Ax b. Matrix A matrix is an m ... Example: » » » ¼ º «

Eigenvalue and Eigenvector

We say that x is an eigenvector of a square matrix A if

xAx

is called eigenvalue and is called eigenvector.

The transformation defined by A changes only the

magnitude of the vector x

Example:

x

1

15

5

5

1

1

41

23

1

22

2

4

1

2

41

23and

5 and 2 are eigenvalues, and

1

1

1

2and are eigenvectors.

Page 26: Review of Linear Algebra - people.scs.carleton.capeople.scs.carleton.ca/~roth/comp4102a-14/notes/lect2_linear_algebra...Ax b. Matrix A matrix is an m ... Example: » » » ¼ º «

Properties of Eigen Vectors

• If 1, 2,…, q are distinct eigenvalues of a

matrix, then the corresponding eigenvectors

e1,e2,…,eq are linearly independent.

• A real, symmetric matrix has real eigenvalues

with eigenvectors that can be chosen to be

orthonormal.

Page 27: Review of Linear Algebra - people.scs.carleton.capeople.scs.carleton.ca/~roth/comp4102a-14/notes/lect2_linear_algebra...Ax b. Matrix A matrix is an m ... Example: » » » ¼ º «

SVD: Singular Value Decomposition

TUDVA

An mn matrix A can be decomposed into:

U is mm, V is nn, both of them have orthogonal columns:

IUU T

D is an mn diagonal matrix.

IVV T

Example:

10

01

00

30

02

100

010

001

00

30

02

Page 28: Review of Linear Algebra - people.scs.carleton.capeople.scs.carleton.ca/~roth/comp4102a-14/notes/lect2_linear_algebra...Ax b. Matrix A matrix is an m ... Example: » » » ¼ º «

Singular Value Decomposition

•Any m by n matrix A can be written as product of three

matrices A = UDVT

•The columns of the m by m matrix U are mutually

orthogonal unit vectors, as are the columns of the n by

n matrix V

•The m by n matrix D is diagonal, and the diagonal

elements, are called the singular values

•It is the case that

•A matrix is non-singular if and only all of the singular

values are not zero

•The condition number of the matrix is

•If the condition number is large, then then matrix is

almost singular and is called ill-conditioned

021 n

i

n

1

Page 29: Review of Linear Algebra - people.scs.carleton.capeople.scs.carleton.ca/~roth/comp4102a-14/notes/lect2_linear_algebra...Ax b. Matrix A matrix is an m ... Example: » » » ¼ º «

Singular Value Decomposition

•The rank of a square matrix is the number of linearly

independent rows or columns

•For a square matrix (m = n) the number of non-zero

singular values equals the rank of the matrix

•If A is a square, non-singular matrix, it’s inverse can be

written as where

• The squares of the non zero singular values are the

non-zero eigenvalues of both the n by n matrix

and of the m by m matrix

•The columns of U are the eigenvectors of

•The columns of V are the eigenvectors of

TUVDA 11 TUDVA

AAT

TAATAA

AAT