Chapter 4 Matrices 1 Learning Objectives In this chapter, you will learn how to: carry out matrix operations; recognise the terms zero matrix, identity matrix, singular and non-sigular evaluate determinants,find inverse matrices and know how to use identities such as (��)−1 = �−1 �−1 ; apply geometric transformations, such as rotations and enlargements, as well as being aware of the relation between scale factor and determinants. Introductions Matrices are a way to present and change numbers and they help you to use rules or find patterns within numbers. Matrices are used extensively in scientific fields, as they can be used to manage large amounts of data. They are widely used in computing processes, for instance reflection and refraction in computing graphics or computer modelling of probabilities for weather forecasting. Many careers and industries use matrices, for example: If you were an accountant or bookkeeper, you might use matrices to record, track and display sales and the movement of money or goods. 1 If you were a physicist you would use matrices in many fields, from the study of quantum mechanics and electronics to optics. If you were responsible for determining the most efficient route for a delivery driver, you could represent it by using matrices. The ability to write the relationships between elements as matrices means that you can then apply algorithms to a wide range of inputs. If you were a video game programmer you would use matrices to transform shapes as the field of view is moved by the player, and to help illustrate the projection of 3D objects into 2D shapes This needs to be done quickly and efficiently, so having a 'rule' in the form of a matrix that the points of a shape follow allows the game to move more quickly and smoothly. If you worked as a software encryption programmer you would use matrices and inverse matrices to code or encrypt messages sent over the internet-for example, bank details or business documents. So, what are the matrices? Matrices(singular, matrix)are rectangular arrays of numbers, variables or expressions arranged in rows and columns. The size of a matrix is defined by its rows - m, and columns - n.We refer to matrices by their order or size, m×n--we read ‘order m by n’. 2 For a general matrix of order m×n we have amn inside represents an element of the matrix. �11 �12 �13 ⋯ �21 �22 �23 ⋯ . Each �31 �32 �33 ⋯ ⋮ ⋮ ⋮ ⋱ For example, the column vector we have learned, is the simplest form matrix. 1 2 3 is a matrix of order 3×1. A matrix that has the same number of rows and columns is called a square matrix. Example 1: A retailer is recording which colours of T-shirt she sells, and whether they are sold at her online shop or in her store in the high street of a town. On Monday she records her sales in this grid. The results can be written in a matrix, giving the matrix M shown above.Working with matrices may help the retailer keep track of her sales. We can use matrix M to represent number of sales on Monday. 4.1 Operations M= 3 2 4 1 2 10 4.1.1 Matrix addition, subtraction Rules: To add together two matrices you need to add the corresponding elements. This is only possible if the two matrices are of the same order. 3 In the example above,the retailer wishes to add together number of sales from Monday and Tuesday. 3 2 1 2 Monday: M = 4 10 Tuesday: T = 0 2 7 3 −1 8 Tips: A negative sign in this context would mean an item being returned. 3 2 4 0 2 7 + 1 2 10 3 −1 8 3+0 2+2 4+7 3 = = 1 + 3 2 − 1 10 + 8 4 M+T = 4 11 1 18 A zero matrix, O, or null matrix is an m×n matrix consisting of all 0s. Adding the zero matrix to another m×n matrix does not change it-in the same way that adding 0 to a number does not increase or decrease it. 4.1.2 Scalar Multiplication of Matrix To multiply a matrix by a scalar you must multiply each of the elements within the matrix by the scalar. The scalar can be positive or negative, and does not have to be an integer. The retailer may notice that number of sales of all items on Wednesday were double sales on Monday. Hence, W=2xM W=2× = 6 2 3 1 4 4 2 1 2×3 = 2 10 2×1 2 20 2×2 2×1 2 × 2 2 × 10 Some basic rules of these operations: Commutative law; Distributive law; Associative law 4 4.1.3 Matrix Multiplication Unlike addition and scalar multiplication, matrix multiplication does not involve simply multiplying the equivalent elements. For previous example, suppose the retailer's T-shirts have different prices, as shown in this table. Find the earnings of online and in-store on Monday. 4.5 You can write the prices as C = 3.5 . 4 4.5 3 2 1 3 × 4.5 + 2 × 3.5 + 1 × 4 × 3.5 = So, M × C = 1 2 10 1 × 4.5 + 2 × 3.5 + 10 × 4 4 36.5 = 51.5 Example 2 Suppose Amy and Bob go to a baker’s shop to buy cakes, doughnuts and eclairs. The numbers of each that they buy is given by the array of numbers. Cakes Doughnuts Eclairs Amy 2 1 1 Bob 4 0 2 Suppose there are actually 2 shops, X and Y, that they could buy at, and the prices are given in the table below, in pence. Shop X Shop Y Cakes 40 45 Doughnuts 30 25 Eclairs 50 40 5 Now they want to compare how much they could spend in each shop. The money Amy would spend in X is: 2 × 40 + 1 × 30 + 1 × 50 = 160. The money Amy would spend in Y is: 2 × 45 + 1 × 25 + 1 × 40 = 155. The money Bob would spend in X is: 4 × 40 + 0 × 30 + 2 × 50 = 260. The money Bob would spend in Y is: 4 × 45 + 0 × 25 + 2 × 40 = 260. 40 45 2 1 1 The purchase matrix is P = , the cost matrix is C = 30 25 . Therefore, 4 0 2 50 40 40 45 2 1 1 PC = P × C = × 30 25 4 0 2 50 40 2 × 40 + 1 × 30 + 1 × 50 2 × 45 + 1 × 25 + 1 × 40 = 4 × 40 + 0 × 30 + 2 × 50 4 × 45 + 0 × 25 + 2 × 40 160 155 = . 260 260 We could deduce the rule of matrix multiplication: the element in the first row and the first column of PC is a11 calculated by the product of the first row of P and the first column of C. More generally the element in the ith row and jth column of PC is aij the product of the ith row of P and the jth column of C. Consider 2 matrices, A = AB = ae + bg af + bh . ce + dg cf + dh a b c d and B = e f , the product of them g h The rules for matrix multiplication: A(B+C) = AB+AC (B+C)A = BA+CA A(BC) = (AB)C s(AB) = (sA)B = A(sB) AO = OA = O 6 Questions: whether AB is equal to BA? Check by examples. Generally, AB ≠ BA. The distributive law is not applied. Investigate the multiplication of non-square matrices. How is the size of the resulting matrix related to the matrices being multiplied together? A matrix product may not exist. ��×� ��×� = �� �×� exits, the number of column of A should be equal to the number of row of B. A and B are called conformable. A special case, for square matrix A, AmAn = AnAm = Am+n. 4.1.3 Matrix Division - the inverse matrix When we carry out the division of numbers, for example, ax = b , 1 therefore we get x = a × b , the 1 � is the inverse of a, or reciprocal. We 1 could check the answer ax = a × a × b = b. Think about: If matrix equation AX = B or XA = B, can you find X using similar method? Before solving the equation, we should find the inverse of matrix A first. We will introduce a new definition. The identity matrix, denoted by I, is a square form in which the elements in the leading diagonal are all 1 and all other elements are 0, I= 100⋯0 010⋯0 001⋯0 . ⋮ ⋮ ⋮ ⋱ ⋮ 000⋯1 In general, we can say that ��×� ��×� = ��×� ��×� = ��×� , provided that the matrix multiplication is allowed. It is just like multiplying any number by 1. 7 Question: Give matrix A, could you find a matrix, such that AX = XA = I? Answers: Sometimes, if A is squared. If AC = CA = I , C is called the inverse of A, denoted by C = A−1 , A = C−1 . The matrix A is said to be non-singular. If no such matrix exists, then A is said to be singular. A square matrix A has an inverse �−� , if and only if, A is non-singular. Then: A−1 AX = A−1 B AX = B X = A−1 B. A−1 A X = A−1 B IX = A−1 B Then how to find an inverse? We will introduce 2 methods. First we will look at the inverse of a 2 × 2 square matrix. Example 3 Given A = Method 1: Let A−1 = 2� + 2� 4� + 5� 2 2 , find A−1 . 4 5 w y . We need x z w y 2 2 1 0 × = . x z 4 5 0 1 2� + 2� 1 0 = , solve simultaneous equations of wx and yz, you 4� + 5� 0 1 5 will get w = 2 , x =− 2, y =− 1, z = 1. Therefore A−1 = 5 2 −2 −1 = 1 5 2 −4 1 −2 . 2 � � , determinant of A, denoted by det(A) is calculated by ad-bc, � � � � i.e.,���(�) = = �� − ��. � � In the previous example, the denominator of the coefficient, 2 is calculated by 2 2 det(A) = = 2 × 5 − 2 × 4. 4 5 � � So, the inverse of non-singular � × � matrix � = is given as �−� = � � Actually, if � = 8 � −� be zero. −� . You could also notice that the det of a non-singular matrix cannot � � ��−�� Method 2: Row operation - augmented matrix � ⋮ � . We use the method of row operation to find the inverse. � ⋮ � ↔ (�−� � ⋮ �−� �) ↔ � ⋮ �−� Row operations are used to change the elements of matrices. There are three types of row operations: Row switching, where �� ↔ �� Row multiplication, where �� → ��� Row addition, where �� → �� + ��� Therefore, the row operations carried out is generally the inverse operation, if A is changed to I through these processes, then I will also be changed to �−1 through the same operations. 22 ⋮10 45 ⋮01 Therefore, A−1 = �2→�1 ×(−2)+�2 �1→�1÷(2) 5 2 −2 2 2 ⋮ 1 0 �1→�2×(−2)+�1 2 0 ⋮ 5 − 2 0 1 ⋮− 2 1 0 1 ⋮− 2 1 1 0 ⋮ 5/2 − 1 01⋮ −2 1 −1 = 1 5 2 −4 1 −2 . 2 Actually we usually use this method to calculate the inverse of higher order non-singular square matrices. 1 Example 4 Given A = 0 2 We then use augmented matrix 1 2 0 −1 2 3 1⋮1 0 0 2⋮0 1 0 1⋮0 0 1 r3 →r2 ×(−1)+r3 r1→r2×2+r1 2 1 −1 2 , find A−1 . 3 1 1 2 0 −1 2 3 1 2 1⋮1 0 −1 2 ⋮ 0 0 −1 −1⋮−2 r3 →r1 ×(−2)+r3 1 2 1⋮1 0 −1 2 ⋮ 0 0 0 −3⋮−2 1 0 5⋮1 0 −1 2 ⋮ 0 0 0 −3⋮−2 0 1 −1 2 1 −1 1⋮1 0 0 2⋮0 1 0 1⋮0 0 1 0 0 1 0 0 1 r3 →r2 ×(−1)+r3 r1 →3r1 +5r3 9 to find the inverse. 0 0 1 0 0 1 1 2 1⋮1 0 0 0 −1 2 ⋮ 0 1 0 0 0 −3⋮−2 −1 1 3 0 0 ⋮−7 0 −1 2 ⋮ 0 0 0 −3⋮−2 1 1 −1 5 0 1 3 0 0 ⋮−7 0 −3 0 ⋮−4 0 0 −3⋮−2 r2 →3r2 +2r3 1 −1 −1 r1 → r1, r2 → r2 ,r3 → r3 3 3 3 −1 Therefore, � = 1 1 −1 5 2 1 7 1 5 3 3 3 1 0 0⋮ 4 1 2 0 1 0⋮ − − 3 3 0 0 1⋮ 3 2 1 1 − 3 3 3 7 −3 4 3 2 3 1 3 1 − 5 3 2 −3 −3 1 3 1 −3 1 =3 −7 1 5 4 −1 −2 . 2 1 −1 The left side of the augmented matrix is now in reduced row echelon form with ones in the leading diagonal and zeros everywhere else. After-class Question: What would happen if you performed column operations instead of row operations? Would the same results be observed? Can column operations work on augmented matrices? What is the difference between the row and column operations? Question: How to find the inverse of the product matrix AB, denoterd by(��)−1 ? (AB)C = C(AB) = I, so C is called the inverse of product matrix AB. (AB)C = I BC = A−1 A−1 (AB)C = A−1 I B−1 (BC) = B−1 A−1 Therefore, (��)−1 = B−1 A−1 . (A−1 A)BC = A−1 BC = A−1 (B−1 B)C = B−1 A−1 C = B−1 A−1 What about (���)−1 ,(���)−1 ? Example 5 4 5 , show that �2 − 7� + 2� = 0. And use this to find �−1 . 2 3 26 35 �2 = , �2 − 7� + 2� = 0. 14 19 M= 10 �2 − 7� + 2� = 0 �2 − 7� =− 2� �(� − 7�) =− 2� 1 1 − �(� − 7�) = �. ∴ �−1 =− (� − 7�) 2 2 Tips: The notation of augmented matrix is �. Therefore, the process of row operations is the multiplication by �−1 to the left of matrix A, to change it to I. 11 4.1.4 Determinants We have already know how to calculate the determinant of a 2 × 2 square matrix. Now let us look at the 3 × 3 square matrix. First some definitions 2 1 should be given. Given a 3 × 3 square matrix M = 3 4 −1 0 a. Minor −2 0 . 1 The minor of each element in the matrix, is the leaving part after crossing out the corresponding row and column of the element, for example, the minor of the 2 is 4 0 0 = 4 . If the element is denoted by a, then the 1 corresponding minor is denoted by A. b. Co-factor The co-factor of each element is the sign of the corresponding position multiply the corresponding minor. The corresponding signs of each element is determined by the position, for example, the sign of element aij + is (-1) . So the sign matrix of a 3 × 3 square matrix is − + 3 0 The co-factor of 2 is 4, the co-factor of 1 is ( − 1)1+2 −1 1 i+j c. The adjugate matrix of M is denoted by adjM. a b c If M = d e f , the co-factor matrix is g h i − + + − . − + =− 3. A −B C −D E −F , the G −H I A −D G adjM = −B E −H , it is a transposed matrix of the co-factor C −F I matrix, just swapping the rows and columns. Then we can calculate the determinant of a 3 × 3 square matrix. The 12 overall determinant is solved by multiply each element of any row or column by corresponding co-factors, i.e., detM = aA − bB + cC =− dD + eE − fF = gG − hH + iI(Row) = aA − dD + gG =− bB + eE − hH = cC − fF + iI(Column) In the given example, detM = 2 × 4 + 1 × ( − 3) + ( − 2) × 3 4 =− 3. −1 0 We can easily find that some elements in the matrix are 0, then we could use the row consisting of 0 to calculate determinants, which will save some calculations. For example, using the last row, detM = ( − 1) × 1 4 −2 2 1 +1× =− (0 + 8) + (8 − 3) =− 3. 0 3 4 We could also use adjM and detM to calculate the inverse of M. 4 −1 8 In the given example, adjM = −3 0 −6 4 −1 5 −3 0 0 1 0 M × adjM = 0 −3 0 = −3 0 1 0 0 −3 0 0 adjM , 0 0 =− 3I = detM I, 1 M × detM = I, then according to the definition, �−1 = Although AB ≠ BA, det(AB) = det(BA) = detA × detB. 1 ���� × ����. Question: Investigate the effects of 3 kinds of row operations on the determinant of the matrix. Row switching, where �� ↔ �� ------------- multiply by (-1) for each switch Row multiplication, where �� → ��� ------ multiply by factor k Row addition, where �� → �� + ��� ------- do not change 13 4.2 Transformations Photo-editing software and video games need to be able to move points and transform images. Matrices are useful in transformations - in particular, transformation that keep origin fixed but move other points. Let the transformation matrix be M. You can show the transformation of x x' any point (x, y) to its image (x , y ) as: M y = ' . We are going to see y ' ' different kinds of matrices M, i.e., corresponding transformations. We consider the rectangle A(1,1), B(1,3), C(5,3) and D(5,1),we can put these coordinates into a matrix to get 1155 . This is formed by 1331 considering each vertex of the rectangle as a position vector. If we multiply this matrix by a 2 × 2 matrix to produce a transformation, we need to multiply in the correct order. For example, there is no change when multiplying by the identity matrix. 1155 . 1331 1 0 0 1 1155 = 1331 4.2.1 Stretch Consider the transformation 1 0 0 2 1155 1155 = . Each y 1331 2662 value has doubled now. This is a stretch of scale factor 2 in the y-direction: the distance relative to the x-axis has been doubled. If we multiply 1144 1331 by the matrix 2 0 , we get 0 1 2 2 8 8 . 1 3 3 1 Similarly, this is a stretch of scale factor 2 in the x-direction: the distance relative to the y-axis has been doubled. Combining the previous two 14 examples, we can see that matrix 2 0 0 2 has the effect of an enlargement of the scale factor 2, measured from the origin, so we can say the origin is the center of enlargement. In each of these three examples we can see an invariant line or point. In the first example, any point on the line y=0 will not change its y value. It is, therefore,invariant. In the second example,any point on the line x=0 15 will not change its x value. It is also, therefore, invariant. In the third example, both x=0 and y=0 are invariant lines. The point where they meet, in this case the origin, is known as an invariant point. � � . � � � � For a stretch in the y-direction of scale factor k,the matrix is represented by . � � For an enlargement relative to the point (0,0) of scale factor k, the matrix is � � represented by . � � For a stretch in the x-direction of scale factor k, the matrix is represented by Any point that is unchanged by a transformation is known as an invariant point. If that point is not the origin, then it must lie on an invariant line. Now consider the matrix 1 2 0 0 1 2 2 8 8 and apply the transformation 2 6 6 2 . We have a scale factor again, but this time it is a reducing factor. 2 What is more interesting is if A = 1 2 0 0 1 2 0 1 2 0 , then A−1 = 4 2 0 0 = 2 . Applying an inverse matrix will revert any transformation to its 2 original state since �−1 � = �. In all of the previous cases the area of the shape is increased by a factor that is equal to the size of the determinant that is transforming the shape. Take,for example, the matrix A = 3 0 . This stretches by factors 3 and 0 2 2, so the area of the new shape is six times as large since det(A)=6. Question: Apply the matrix 4 3 1 1 to the triangle represented by the points (1,1), (4,1) and (4,5). What do you notice about the area of the image of the triangle? How does this relate to the determinant of the matrix being applied? 16 As well as stretching and enlarging, we can also consider rotations and reflections as transformations. 4.2.2 Reflections Consider the triangle represented by the points(1,1),(1,4),(4,1). As always,we write these coordinates in matrix form 1 1 4 . 1 4 1 Consider reflecting the triangle in the y-axis. That is, the effect of this matrix is to change the sign of each x value but not to change the y values. −1 0 , i.e., 0 1 −1 0 1 1 4 −1 −1 −4 = . 0 1 1 4 1 1 4 1 1 0 Similarly, the reflection matrix in the x-axis is . 0 −1 So the reflection matrix in the y-axis is 4.2.3 Rotations When we apply both of these transformations, in either order, to the 1 4 then the result is 4 1 1 0 −1 0 1 1 4 −1 0 = 0 −1 0 1 1 4 1 0 1 −1 −1 −4 . −1 −4 −1 triangle 1 1 17 1 0 0 −1 1 1 1 4 4 = 1 This effect is a rotation about the origin by 180°. We multiply the two reflection matrices, we get the rotation matrix of 180° is This 180° can be considered to be clockwise or anticlockwise. −1 0 . 0 −1 Now we will generalize the rotation matrix. Example 6 Find the matrix which represents a rotation through an angle θ anticlockwise about the origin. The original points A(0,1) and C(1,0) are rotated through an angle θ anticlockwise about the origin. The images are �' ( cos � , sin � ) and �' ( −sin � , cos � ) . So this rotation matrix about the origin by θ in the anticlockwise direction is cos � − sin � . sin � cos � Example 7: Find the matrix which represents a reflection in the line y = x. Any point x, y reflects to point y, x in the line y = x. b , then we have the relation d 1 3 2 4 0 1 a b = , we get = 2 4 1 3 1 0 c d Let the transformation matrix be a b c d a c 18 Question: Find the matrix which represents a reflection in the line at an angle θ to the x-axis. Example 8 Describe the effect of the following matrices on the triangle given by (1,1), (3,1), (1,3). Illustrate your findings. a. −2 0 Answers: 0 1 b. a. Shape is reflected in the y-axis. 1 0 0 −2 c. −2 0 0 −2 Shape is stretched by a scale factor of 2 in the x-direction. Area is doubled since the magnitude of the determinant is 2. b. Shape is reflected in the x-axis. Shape is stretched by a scale factor of 2 in the y-direction. Area is doubled since the magnitude of the determinant is 2. c. Shape is rotated 180°clockwise or anticlockwise about the origin. Shape is enlarged relative to the origin by a scale factor of 2. Area is four times since the magnitude of the determinant is 4. 19 4.2.3 Shear Consider the matrix 1 1 . If we apply it to the rectangle (1,1), (3,1), 0 1 (3,5), (1,5), then each point is translated parallel to the x-axis since the new x-coordinates are based on x +y. This effect is called a shear. The distance through which points are displaced depends on their distance from the line x = 0. Consider the rectangle (1,0), (3,0), (3,4), (1,4). If we apply the same matrix to these points, we get a different shear. This time only the top points move since the two bottom vertices lie on an invariant line,y = 0. As we can see in this diagram, the top points have a y value that is unchanged by the shearing factor. So a matrix of the form 1 � 0 1 will produce a shear in the x-direction, and the distance each point is moved is equal to ky0 , where is y0 is the original y value. Similarly, a matrix of the form 1 0 2 1 should give a shearing effect in the y-direction instead. Apply this matrix to the rectangle with vertices 20 (0,0), (0,3), (2,3) and (2,0). This gives 1 2 0 1 0 0 2 2 = 0 3 3 0 0 0 2 2 . We can see that the line x=0 is invariant and any point on 0 3 7 4 this line does not change. So any matrix of the form Question: Apply the matrix 1 0 � 1 1 0 will produce a shear in the y-direction. � 1 to sets of points and investigate with different values of k. What happens in the cases where 0<k<1 or k<0? 4.2.4 Invariant points and invariant lines Points that transform to themselves (i.e. are not affected by the transformation) are called invariant points. In a reflection, the points on the mirror line remain unchanged by the reflection. Enlargements, with centre of enlargement (0, 0), only have one point that does not move, namely the origin. Consider this product, 4 3 2 3 2 2 = . It −2 −2 means that the point (2,-2) is transformed onto itself, and so (2,-2) is an invariant point for the matrix 4 3 . 2 3 To find the invariant points you can consider the general point x, y . 21 4 3 2 3 x x x 4x + 3y 4x + 3y = x = → = . So → y =− x. y y y 2x + 3y 2x + 3y = y So all the points on the line y=-x are invariant. If you simplify both expressions and get different results it means that there is only one invariant point: the origin. Invariant lines are slightly less particular than invariant points. All points on an invariant line will be transformed to a point on the same line. KEY Information: Invariant points transform to themselves. Invariant lines have points that are transformed to another point on the same line. Invariant points may join up to form a line of invariant points. For any reflection, invariant lines are all lines perpendicular to the mirror line, together with the mirror line itself (which is called a line of invariant points).The original points are labelled: D,E,F, etc. with their associated images: D',E',F',etc. A and B are on the mirror line, so the image is not labelled. 22 The diagram below illustrates that for an enlargement any line that passes through the origin is an invariant line, even though the origin is the only invariant point. For most rotations there are no invariant lines, with one exception: a rotation of 180. In this case, any line that passes through the origin is an invariant line, even though the origin is the only invariant point. So we understand that points on the invariant lines do not mean the points are invariant. If we wanna find the invariant points, we could use the x x previous method by solving equation A y = y . But for finding the invariant lines, the method may be different. Example 9 Find the invariant lines for the matrix 1 −2 . −2 1 Suppose the invariant line is y = mx. The image of point x, y invariant line is on the X, Y . And also there are relations y = mx, Y = mX . Consider the matrix equation below: 1 −2 x X 1 −2 = → y −2 1 Y −2 1 23 x X = mx mX → x − 2mx = X −2x + mx = mX Divide the first equation by the second to get 1−2m −2+m = 1 m . Solve the equation to give �2 = 1, �� � =± 1. This means there are two invariant lines, � =± � . They meet at the origin, which is always an invariant point. 24