FP1: Chapter 4 Matrix Algebra

52
FP1: Chapter 4 Matrix Algebra Dr J Frost ([email protected]) Last modified: 29 th August 2015

description

FP1: Chapter 4 Matrix Algebra. Dr J Frost ([email protected]) . Last modified: 10 th February 2014. Introduction. A matrix (plural: matrices) is simply an ‘array’ of numbers , e.g. - PowerPoint PPT Presentation

Transcript of FP1: Chapter 4 Matrix Algebra

Page 1: FP1: Chapter 4  Matrix Algebra

FP1: Chapter 4 Matrix Algebra

Dr J Frost ([email protected])

Last modified: 29th August 2015

Page 2: FP1: Chapter 4  Matrix Algebra

Introduction

A matrix (plural: matrices) is simply an ‘array’ of numbers, e.g.

But the power of matrices comes from being able to multiply matrices by vectors and matrices by matrices and ‘invert’ them: we can:

1. represent linear transformations using matrices (e.g. rotations, reflections and enlargements)

2. Use them to solve linear simultaneous equations.

The first of these means matrices are particularly useful in 3D graphics/animation, since they allow us to rotate the camera and project 3D data onto a 2D viewing plane. But matrices are used everywhere, including robotics, computer vision, optimisation, classical and quantum mechanics, electromagnetism, optics, graph theory, statistics, ...

On a simple level, a matrix is simply a way to organise values into rows and columns, and represent these multiple values as a single structure.

Page 3: FP1: Chapter 4  Matrix Algebra

Using matrices to represent dataThis is a scene from the film Good Will Hunting.Maths professor Lambeau poses a difficult* problem for his graduate students from algebraic graph theory, the first part asking for a matrix representation of this graph. Matt Damon anonymously solves the problem while on a cleaning shift.

* It really isn’t.

?

In an adjacency matrix, the number in the ith row and jth column is the number of edges directly connecting node (i.e. dot) i to dot j

?

Page 4: FP1: Chapter 4  Matrix Algebra

Using matrices to represent data

In my 4th year undergraduate dissertation, I used matrices to help ‘learn’ mark schemes from GCSE biology scripts. Matrix algebra helped me to initially determine how words (and more complex semantic information) tended to occur together with other words.

Page 5: FP1: Chapter 4  Matrix Algebra

Using matrices to represent data

In S1, you learnt how we could extend the idea of variance (i.e. how much a variable varies) to that of covariance (i.e. how much two variables vary with each other). A covariance matrix allows us to store the covariance between variables all in one convenient structure.

This allows us for example to extend a Normal Distribution from one dimension (i.e. involving just one variable) to multiple dimensions.

1D 2D

Page 6: FP1: Chapter 4  Matrix Algebra

ζMatrix FundamentalsMatrix Algebra

Understand the dimensions of a matrix, and operations on matrices, such as addition, scalar multiplication and matrix multiplication.

Page 7: FP1: Chapter 4  Matrix Algebra

Matrix Fundamentals#1 Dimensions of MatricesThe dimension of a matrix is its size, in terms of its number of rows and columns.

Matrix Dimensions

2 3

3 1

1 3

?

?

Page 8: FP1: Chapter 4  Matrix Algebra

Matrix Fundamentals#2 Notation/Names for MatricesA matrix can have square or curvy brackets*.

* The textbook only uses curvy.

Matrix Column Vector(The vector you know

and love)

Row Vector

So a matrix with one column is simply a vector in the usual sense.

Page 9: FP1: Chapter 4  Matrix Algebra

Matrix Fundamentals#3 Variables for MatricesIf we wish a variable to represent a matrix, we use bold, capital letters.

𝑨=( 16−3)

Page 10: FP1: Chapter 4  Matrix Algebra

Matrix Fundamentals

#4 ElementsEach value within a matrix is known as an element.If A is a matrix, then we can refer to the element in the ith row and jth column as .

Note that you do not need to know this notation for referencing elements for the purposes of FP exams, but it’s worthwhile knowing.

?? ?

Page 11: FP1: Chapter 4  Matrix Algebra

Matrix Fundamentals

#5 Adding/Subtracting MatricesSimply add/subtract the corresponding elements of each matrix.They must be of the same dimension.

?

?

Page 12: FP1: Chapter 4  Matrix Algebra

Matrix Fundamentals

#6 Scalar MultiplicationA scalar is a number which can ‘scale’ the elements inside a matrix/vector.

?

?

?

1

2

3

Page 13: FP1: Chapter 4  Matrix Algebra

Matrix Fundamentals

#7 Matrix MultiplicationThis is where things get slightly more complicated...

1 0 3 -22 8 4 37 -1 0 2

5 1 1 7 0 3 8 -3

-11

We start with this row and column, and sum the products of each pair.(1 x 5) + (0 x 1) + (3 x 0) + (-2 x 8) = -11You will see in C4 that this is known as finding the “dot/scalar product” of the two vectors.

16

Now repeat for the next row of the left matrix...

42 61

50 -6

Page 14: FP1: Chapter 4  Matrix Algebra

=

Matrix Fundamentals

#7 Matrix MultiplicationNow you have a go...

?

?

?

?

(1 2 3 )(123)= (14 )?

?

a

b

c

d

e

f

Page 15: FP1: Chapter 4  Matrix Algebra

Matrix Fundamentals

#7 Matrix MultiplicationMatrix multiplications are not always valid: the dimensions have to agree.

Note that only square matrices (i.e. same width as height) can be raised to a power.

Dimensions of A Dimension of B Dimensions of AB (if valid)

2 3 3 4 2 4

1 3 2 3 Not valid.

6 2 2 4 6 4

1 3 3 1 1 1

7 5 7 5 Not valid.

10 10 10 9 10 9

3 3 3 3 3 3

???????

Page 16: FP1: Chapter 4  Matrix Algebra

Exercise 4C

Q1, 3, 5, 6, 8, 9

Page 17: FP1: Chapter 4  Matrix Algebra

ζLinear TransformationsMatrix Algebra

Appreciate what linear transformations are, and how we can use matrices to represent them.

Page 18: FP1: Chapter 4  Matrix Algebra

Position vectors

You should be familiar with the difference between a vector and a point:

Point: represents a position in space.Vector: represents a movement.

A position vector allows us to treat a point as a vector.A position vector [x y] represents the movement from the origin (0,0) to the point (x,y).

??

x

y

Point (5,3)Position vector [5 3]

For the remainder of the chapter, when I say ‘point’, I really mean ‘position vector’.

Page 19: FP1: Chapter 4  Matrix Algebra

Linear FunctionsFrom GCSE, you are used to a linear function looking like the equation of a straight line:

More generally, if we had multiple inputs, a linear function is:

When the inputs and outputs of the function are vectors however, then we have a linear map/transformation if:

The first condition ensures that if we scale the original point x, then this scales the transformed point too. The second says that if we add two vectors, then resulting vector will be the same then if we transformed each of the vectors individually then added them – we say that the transformation ‘preserves vector addition and scalar multiplication’.

and represent vectors here not the and value of a vector.

Page 20: FP1: Chapter 4  Matrix Algebra

Linear Transformations

𝑓 (𝟎 )=𝟎This follows by letting the scalar in This means that the origin is unaffected by a linear transformation.

Suppose that 0 is the 0-vector, i.e. The position vector (0,0) in 2D, (0,0,0) in 3D, etc.Then for a linear transformation f:

?

Can you express the following transformations as functions?If linear, prove it, otherwise find a counterexample.

Example 1 Reflects a 2D point in the y-axis.

Proof of linearity:

?

?

Page 21: FP1: Chapter 4  Matrix Algebra

Linear Transformations

Example 2 Rotates a 2D point 90 clockwise about the origin.

Linear? Yes (proof similar to before)

?

?

Example 3 Enlarges by a scale factor of 3 with the origin as the centre of enlargement.

Linear? Yes. Proof:

?

?

Page 22: FP1: Chapter 4  Matrix Algebra

Linear Transformations

Example 4 Projects a 3D coordinate onto the xy-plane, almost as if you were observing a 3D point where your viewing window/eyes are the xy-plane.

Linear? Yes (proof left as exercise)

?

?This is useful in 3D graphics, because you need to turn 3D data into a 2D image by projecting onto a viewing plane.

Example 5 Translate a 2D point 1 unit to the right.

?

Linear? No! The origin is not preserved.?

Page 23: FP1: Chapter 4  Matrix Algebra

Linear Transformations

As we have seen, the following transformations are linear and not linear:

•Reflection (where line of reflection goes through the origin)•Rotation (with centre at the origin)•Enlargement (with centre at the origin)

Linear Non-Linear•Translation.

! A linear transformation in general is when each output is a linear combination of the inputs, e.g:

While a transformation can create or destroy dimensions, in FP1 we’ll just be dealing which transformation which transform 2D points to 2D points.

Page 24: FP1: Chapter 4  Matrix Algebra

Affine Transformations (Not mentioned in FP1)

Affine transformations extend linear transformations by allowing a constant term. This hence allows us to represent translations.

𝑓 (𝑥𝑦 )=(2 𝑥+𝟏𝑥−𝑦 )𝑓 (𝑥𝑦 )=( 2 𝑥𝑥− 𝑦 )

Linear Affine

𝑓 (𝑥𝑦 )=( 𝑥+𝟏𝑦−𝟐)

Linear TransformationsThe following examples are NOT linear transformations:(can you prove it?)

𝑓 (𝑥𝑦 )=(𝑥𝑦𝑦 ) 𝑓 (𝑥𝑦 )=(𝑥2𝑦 )

Page 25: FP1: Chapter 4  Matrix Algebra

Using Matrices for Linear Transformations

Matrices allow us to represent all possible linear transformations.

Reflection in -axis:

𝑓 (𝑥𝑦 )=(−𝑥𝑦 ) (−𝟏 𝟎𝟎 𝟏)(𝑥𝑦 )=(− 𝑥𝑦 )?

Rotation 90 clockwise about the origin.

𝑓 (𝑥𝑦 )=( 𝑦−𝑥 ) ( 𝟎 𝟏−𝟏 𝟎)(𝑥𝑦 )=( 𝑦− 𝑥)?

Page 26: FP1: Chapter 4  Matrix Algebra

Using Matrices for Linear Transformations

Matrices allow us to represent all possible linear transformations.

𝑓 (𝑥𝑦 )=(2 𝑦+𝑥3𝑥 ) (𝟏 𝟐

𝟑 𝟎)(𝑥𝑦 )=(2 𝑦+𝑥3 𝑥 )

𝑓 (𝑥𝑦 )=( −2 𝑦3 𝑥+𝑦 ) (𝟎 −𝟐𝟑 𝟏 )(𝑥𝑦 )=( −2 𝑦3𝑥+𝑦 )

?

𝑓 (𝑥𝑦 )=(2 𝑦−𝑥3 𝑦+𝑥 ) (−𝟏 𝟐𝟏 𝟑)(𝑥𝑦 )=(2 𝑦−𝑥3 𝑦+𝑥 )

𝑓 (𝑥𝑦 )=(0𝑥) (𝟎 𝟎𝟏 𝟎)(𝑥𝑦 )=(0𝑥)

?

?

?

𝑓 (𝑥𝑦 )=( 2 𝑥𝑥− 𝑦 ) (𝟐 𝟎𝟏 −𝟏)(𝑥𝑦 )=(0𝑥)?

Page 27: FP1: Chapter 4  Matrix Algebra

Basis Vectors and Vector Spaces (Not mentioned in FP1)

Basic vectors are usually (but not necessarily) the unit vectors along each axis.A vector space is all possible points that can be obtained by some linear combination of the basis vectors.

Example: 2D space

Basic vectors: (10)(01)Vector space: All position vectors since

Intuitively this is obvious: any point in 2D space can be obtained by some movement along the axis and some movement along the axis.Our basis vectors could have been any non-parallel vectors.

?

?

Page 28: FP1: Chapter 4  Matrix Algebra

Using Matrices for Linear Transformations

There’s a groovy trick that allows us to work out what matrix to use for a particular transformation. Observe:

(𝑎 𝑏𝑐 𝑑)(10)=(𝑎𝑐) (𝑎 𝑏

𝑐 𝑑)(01)=(𝑏𝑑 )Thus, each column of the matrix tells us how the unit vectors are transformed. These transformed basis vectors form the new vector space.

x

y

(10)

(01)

x

y

(−10 )

(01)

Example: Reflection in -axis.

𝑇=(−1 00 1)?

First column is first basis vector transformed.

? ?

Page 29: FP1: Chapter 4  Matrix Algebra

Using Matrices for Linear Transformations

x(10)

(01)

x(−10 )

(01)

Rotation anticlockwise about the origin. 𝑇=(0 −1

1 0 )?

x(10)

(01)

x

(cos𝜃sin𝜃 )

Rotation anticlockwise about the origin. 𝑇=(cos𝜃 −sin 𝜃

sin 𝜃 cos𝜃 )?

𝜃

(− sin𝜃cos𝜃 )?

?

Page 30: FP1: Chapter 4  Matrix Algebra

Rotation for multiples of

In the FP1 specification, you are only required to identify rotations for multiples of , although the rotation matrix for anticlockwise in general is in your formula booklet.

(cos𝜃 − sin𝜃sin𝜃 cos𝜃 )

(1√2

− 1√2

1√2

1√2

)= 1√2 (1 −1

1 1 )

1√2 (

1 1−1 1)

Rotation of anticlockwise

Rotation of clockwise

Rotation of anticlockwise

1√2 (−1 −1

1 −1)

Bro Tip: To remember these without having to plug in your in the above matrix, just remember the scaling, and then just visually think how each basis vector is transformed to get the signs of the 1s correct.

?

?

?

Page 31: FP1: Chapter 4  Matrix Algebra

Using Matrices for Linear Transformations

x(10)

(01)

x(20)

(02)

Enlargement by scale factor 2 about the origin. 𝑇=(2 0

0 2)?

x(10)

(01)

x(10)

(01)

No change.

𝑇=(1 00 1)?

?

?

This is known as the identity matrix, and is denoted by .

Page 32: FP1: Chapter 4  Matrix Algebra

A quick digression…An identity element in general is a special type of element on a set (e.g. the set of integers, or real numbers, or matrices) with respect to a binary operator on the set.

An element is an identity element if for all in the set and some operator then:

Set Operation Identity Element

0 (since )

1 (since )

square matrices

Matrix multiplication

(since )(e.g , but you tend to just see )

Sets (since )

Boolean Algebra

(since )

matrices Matrix addition

The “0-matrix” .

Vectors The “0-vector” .

(Not mentioned in FP1)

??

?

??

??

Page 33: FP1: Chapter 4  Matrix Algebra

Using Matrices for Linear Transformations

x(10)

(01)

x

Reflection in the line

𝑇=(cos 2𝜃 sin 2𝜃sin 2𝜃 −cos 2𝜃)?

𝑦=

( tan𝜃

)𝑥

𝑦=

( tan𝜃

)𝑥

?

𝜃𝜃

180−2 𝜃

Since for any line of length and inclination , the component is and component , then gradient is consequently , i.e. must be the angle between the axis and line of reflection.

We can see from the diagram above that when we reflect we can form the following triangle:

1

180−2 𝜃

Thus the vector gets transformed to

We can do something similar to transform

Page 34: FP1: Chapter 4  Matrix Algebra

Test Your UnderstandingJan 2011 Q2

June 2011 Q3

Reflections in the -axis.

Enlargement by scale factor 3 about the origin.

A reflection in the line

?

?

?

Page 35: FP1: Chapter 4  Matrix Algebra

Exercise 4EDescribe the transformations represented by the matrix:

a) Reflection in -axis. b) Rotation anticlockwise about .

c) Rotation clockwise about .

And for these:

a) Rotation clockwise about .

b) Enlargement scale factor 4, centre .c) Rotation anticlockwise about .

1

3

4 Find the matrix that represents these transformations.

a) Rotation of clockwise about .

b) Reflection in the -axis.

c) Enlargement centre scale factor 2.

5 Find the matrix that represents these transformations.

a) Enlargement scale factor -4 centre (0,0).

b) Reflection in the line .

c) Rotation about of clockwise.

?

?

?

?

?

?

?

?

?

??

?

Page 36: FP1: Chapter 4  Matrix Algebra

Combined Transformations

We know that for a position vector and a matrix representing some transformation, then is the transformed point.

If we wanted to apply a transformation represented by a matrix followed by another represented by , what transformation matrix do we use to represent the combined transformation?

This is because to apply the effect of followed by , we have:

(because matrix multiplication is ‘associative’*)

Bro Tip: Ensure that you put these matrices in the right order – the first that gets applied is on the right!

* A binary operator is associative if , i.e. when we multiply matrices, the order in which we multiply them doesn’t matter.

?

Page 37: FP1: Chapter 4  Matrix Algebra

Combined Transformations

Represent as a single matrix the transformation representing a reflection in the line followed by a stretch on the axis by a factor of 4.

= ? ? ?

Represent as a single matrix the transformation representing a rotation anticlockwise about the point followed by a reflection in the line .

= ? ? ?

What single transformation is this?Reflection in the axis.?

Page 38: FP1: Chapter 4  Matrix Algebra

Exercise 4F

Page 93Q1, 3, 5, 7

Page 39: FP1: Chapter 4  Matrix Algebra

Matrix Inverses

In maths, we are used to functions having an inverse.

It would seem logical to have some inverse of multiplying something by a matrix, so that we can represent ‘undoing’ the transformation (e.g. the inverse of the matrix representing rotation clockwise would be a matrix representing a rotation anticlockwise).

! If then

• is the ‘inverse’ of , so that if , • since the effect of a transformation followed by its

inverse has no effect.

Page 40: FP1: Chapter 4  Matrix Algebra

Determinants The determinant of a matrix is

So

If , then is a singular matrix and does not exist (since we can’t divide by 0).

If , then is a non-singular matrix and exists.

A det(A)

1

-2

3

-2

????

It’s worthwhile reflecting on the significance of the determinant: in the context of transformations, it ‘determines’ whether we can ‘undo’ a transformation. And later, we’ll see that it can tell us whether a series of simultaneous equations are solvable.

Page 41: FP1: Chapter 4  Matrix Algebra

Practicing the Inverse

𝑎1𝑎𝑑−𝑏𝑐

𝑏𝑐 𝑑−

Divide by determinant.

Swap NW-SE elements.

Make SW-NE elements negative.

Click to Broinverse

Page 42: FP1: Chapter 4  Matrix Algebra

Test Your Understanding

For what value of is singular? Given is not this value, find the inverse.

?

?

?

? ?

Page 43: FP1: Chapter 4  Matrix Algebra

Using

A matrix multiplied by its inverse is the identity matrix.

If and are non-singular matrices, prove that

If then The general strategy for solving these kinds of equations is to multiply whatever’s on the front of the multiplication by its inverse, to ‘cancel it out’.

?

If and are non-singular matrices such that . Prove that .

𝐵𝐴𝐵=𝐼?

Page 44: FP1: Chapter 4  Matrix Algebra

Exercise 4G

Page 97Q1a, c, e2a, c4, 6, 8, 10, 11

Page 45: FP1: Chapter 4  Matrix Algebra

Inverse matrices represent inverse transformations! Suppose and are column vectors. Then if , then .

The inverse matrix therefore allows us to retrieve the original point/position vector before a transformation.

The triangle has vertices at , and . The matrix transforms to the triangle with vertices at and .Sketch the two triangles, and hence show that

So the determinant was the scale factor of the area.

-1 1

(2,4) (4,10)

(4,3)

-4 4

?

Page 46: FP1: Chapter 4  Matrix Algebra

Area scale factorWe saw in this example that:

Area of image Area of object

i.e. the determinant tells us how the area is scaled under the transformation matrix .

Area of Object Transformation Matrix

Area of Image

?

???

Page 47: FP1: Chapter 4  Matrix Algebra

Exam QuestionEdexcel FP1 - Jan 2011

4

14 (3 21 2)

72÷4=18

Note that we’re given the points on the image! So use inverse transformation. So points are .

?

?

?

?

Page 48: FP1: Chapter 4  Matrix Algebra

Exercise 4IThe matrix is used to transform the rectangle with vertices at the points , , and .a) Find the coordinates of the vertices of the image of .b) Calculate the area of the image of .

A rectangle of area 5cm2 is transformed by the matrix . Find the area of the image of the rectangle when is:a) c) e)

The triangle has area 6cm2 and is transformed by the matrix where is a constant, into triangle .a) Find in terms of .b) Given that the area of is 36cm2, find the possible values of .

1

4

5

Area = 40

a) 70 c) 15 e) 90

?

?

?

Page 49: FP1: Chapter 4  Matrix Algebra

Frost Life StoriesTM

In the game Assassin’s Creed II, you encounter a variety of concentric ring picture puzzles, which upon successfully completing, you unlock a segment of a secret video.Rings are connected in pairs, and must be rotated together in their pairs. The aim is to form a complete picture. Different possible pairs can be selected, for example, where there just 3 rings, you could rotate A and B together, B and C together or C and A together. Only certain pairings are available.

Because I’m a massive geek, I formed simultaneous equations and used a matrix inverse to solve them, which therefore told me how many times to rotate each pair.

We’ll see how we can do this.

Page 50: FP1: Chapter 4  Matrix Algebra

Using Matrices For Simultaneous Equations

Turn the following simultaneous equations into a matrix:

( 2 −3−5 6 )(𝑥𝑦)=( 5−8)

Hence, use a matrix inverse to solve these simultaneous equations.

Let . Then

So and .

?

?

Page 51: FP1: Chapter 4  Matrix Algebra

Test your understanding

Solve (using matrices) the simultaneous equations:

So , .

Explain why the following simultaneous equations have no solution:

The matrix has no inverse because the determinant is 0.

Q

Q

?

?

Page 52: FP1: Chapter 4  Matrix Algebra

Exercise 4J

Use inverse matrices to solve the following simultaneous equations.

?

?

?

?

1a

1b

2a

2b