Chapter 2 Matrices Matrices provide an orderly way of arranging values or functions to enhance the analysis of systems in a systematic manner. Their use is very important in simplifying large arrays of equations and in determining their solutions. In particular, computer algorithms for manipulating large arrays are simplified greatly by matrix notation and operations. 1 A particular reason for introducing matrices at this point is that MATLAB is heavily matrix oriented. One does not have to be an expert in matrix theory to utilize the powerful features of MATLAB, but it is very helpful to understand some of the terminology and manipulations. This chapter will deal with those basic elements of matrix theory that can be used for that purpose. The term linear algebra is often used to represent the general theory of matrices and the associated algebraic operations. 2 General Form of a Matrix of Size m x n with m Rows and n Columns a11 a12 a13 ....a1n a a a ....a 21 22 23 2n A : : am1 am 2 am3 ...amn 3 Square Matrix If m = n, the matrix is said to be square. In this case, the matrix could be designated as an m x m matrix. A m,m 4 Vectors A matrix having only one row is called a row matrix. A matrix having only one column is called a column matrix. A matrix of either form is called a vector. The row matrix is called a row vector and the column matrix is called a column vector. 5 Scalars A 1 x 1 matrix is called a scalar and is the form of most variables considered in simple algebraic forms. 6 Transpose The transpose of a matrix A is denoted as A’ and is obtained by interchanging the rows and columns. Thus, if A has a size of m x n, A’ will have a size of n x m. If the transpose operation is applied twice, the original matrix is restored. 7 Example 2-1. Determine the size of the matrix shown below. 2 -3 5 A -1 4 6 The matrix has 2 rows and 3 columns. Its size is 2 x 3. 8 Example 2-2. Determine the size of the matrix shown below. 2 1 B 7 -4 3 1 The matrix has 3 rows and 2 columns. Its size is 3 x 2. 9 Example 2-3. Determine the size of the matrix shown below. 2 -1 3 C 4 6 1 -5 2 1 The matrix has 3 rows and 3 columns. Its size is 3 x 3. It is a square matrix. 10 Example 2-4. Express the integer values of time from 0 to 5 s as a row vector. t [0 1 2 3 4 5] The size of the vector is 1 x 6. 11 Example 2-5. Express the variables x1, x2, and x3 as a column vector. x1 x x2 x3 12 Example 2-6. Determine the transpose of the matrix A below. 2 -3 5 A -1 4 6 2 -1 A' -3 4 5 6 13 Addition and Subtraction of Matrices Matrices can be added together or subtracted from each other if and only if they are of the same size. Corresponding elements are added or subtracted. Cm,n = Am,n ± Bm,n 14 Multiplication of Two Matrices Two matrices can be multiplied together only if the number of columns of the first matrix is equal to the number of rows of the second matrix. This means that AB BA 15 Multiplication of Two Matrices (Continuation) The number of rows in the product matrix is equal to the number of rows in the first matrix and the number of columns in the product matrix is equal to the number of columns in the second matrix. A m,n Bn ,k Cm,k 16 Multiplication of Two Matrices (Continuation) An element in the product matrix is obtained by summing successive products of elements in the row of the first with elements of the column of the second. n cij air brj r 1 17 Division of Matrices ? There is no such thing as division of matrices. However, matrix inversion can be viewed in some sense as a procedure similar to division. This process will be considered later. 18 Example 2-7. Determine C = A + B for the matrices shown below. 3 2 1 A -4 5 6 4 9 x B 6 -3 y 7 11 1+x C 2 2 6+y 19 Example 2-8. Determine D = A - B for the matrices shown below. 3 2 1 A -4 5 6 4 9 x B 6 -3 y -1 -7 1-x D -10 8 6-y 20 Example 2-9. For the matrices of Examples 2-1 and 2-2, determine possible orders of multiplication. 2 -3 5 A -1 4 6 2 1 B 7 -4 3 1 AB A 2,3B 3,2 C2,2 BA B 3,2 A 2,3 D3,3 21 Example 2-10. For the matrices of Examples 2-1 and 2-2, determine C=AB. A = A 2,3 2 -3 5 -1 4 6 B = B 3,2 2 1 2 -3 5 C 7 -4 -1 4 6 3 1 2 1 7 -4 3 1 22 Example 2-10. Continuation. c11 (2)(2) (3)(7) (5)(3) 4 21 15 2 c12 (2)(1) (3)(4) (5)(1) 2 12 5 19 c21 (1)(2) (4)(7) (6)(3) 2 28 18 44 c22 (1)(1) (4)(4) (6)(1) 1 16 6 11 2 19 C 44 -11 23 Example 2-11. For the matrices of Examples 2-1 and 2-2, determine D=BA. A = A 2,3 2 -3 5 -1 4 6 B = B 3,2 2 1 7 -4 3 1 2 1 3 -2 16 2 -3 5 D = BA 7 -4 18 -37 11 -1 4 6 3 1 5 -5 21 24 Determinants The determinant of a matrix A can be determined only for a square matrix. It is a scalar value. Various representations are shown as follows: det(A) A 25 Determinant of 2 x 2 Matrix a11 a12 A a21 a22 det( A) a11a22 a12 a21 26 Determinants of Higher-Order For determinants of matrices of higher order than 2 x 2, the process can become tedious. There are many “tricks”, but some are useful only when the matrix has simple numbers. The text provides a procedure based on minors and cofactors, but since the ultimate goal is to use MATLAB, that procedure will not be covered on these slides. Instead, formulas for the 3 x 3 case will be provided. 27 Determinant of 3 x 3 Matrix a11 a12 A a21 a22 a31 a32 a13 a23 a33 det( A) a11 (a22 a33 a23a32 ) a12 (a21a33 a23a31 ) a13 (a21a32 a22 a31 ) 28 Singular Matrix If det(A)=0, the matrix is said to be singular. If the matrix represents the coefficients of a set of simultaneous equations, it means that the equations are not independent of each other and cannot be solved uniquely. 29 Example 2-13. Determine the determinant of the matrix shown below. 3 2 A -4 5 3 2 det( A ) (3)(5) (2)(4) -4 5 15 8 23 30 Examples 2-13, 2-14, and 2-15 These 3 examples involve computations concerning the minors and cofactors of a 3 x 3 matrix and will not covered in this presentation. The results that follow these computations will be considered in a later example. 31 Identity Matrix 1 0 0....0 0 1 0....0 I 0 0 1....0 : : 0 0 0 ....1 32 Inverse Matrix The inverse of a matrix A is denoted by A-1 and is defined by the equation that follows. 1 1 AA A A I 33 Inverse of a 2 x 2 Matrix a22 -a12 1 -a21 a11 a11 a12 a a det( A) 21 22 -a12 a22 det( A) det( A) a11 -a21 det( A) det( A) 34 Example 2-16. Determine the inverse of the matrix A below. 2 3 A 4 5 det( A) (2)(5) (3)(4) 2 5 -3 1 -4 2 2.5 1.5 2 3 1 A -1 2 4 5 2 35 Example 2-17. The inverse of A below is developed in the text. 1 2 -1 A -1 1 3 3 2 1 -0.25 -0.2 0.35 1 A 0.5 0.2 -0.1 -0.25 0.2 0.15 36 Simultaneous Linear Equations a11 x1 a12 x2 ....a1m xm b1 a21 x1 a22 x2 ....a2 m xm b2 : : : am1 x1 am 2 x2 ....amm xm bm 37 Matrix Form of Simultaneous Linear Equations a11 a12 ....a1m x1 b1 a a ....a x b 2m 2 2 21 22 : : : : am1 am 2 ....amm xm bm 38 Define variables as follows: a11 a12 ....a1m a a ....a 21 22 2m A : : am1 am 2 ....amm x1 b1 x b 2 2 x b : : xm bm 39 Matrix Solution Development Ax b A Ax A b -1 -1 -1 A A=I Ix = x 40 The general form and the final solution follow. Ax = b -1 x=A b 41 Example 2-18. Use matrices to solve the simultaneous equations below. x1 2 x2 x3 8 x1 x2 3x3 7 3x1 2 x2 x3 4 42 Example 2-18. Continuation. 1 2 -1 x1 8 -1 1 3 x 7 2 3 2 1 x3 4 Ax = b 43 Example 2-18. Continuation. -1 x=A b x1 -0.25 -0.2 0.35 -8 x x2 0.5 0.2 -0.1 7 x3 -0.25 0.2 0.15 4 2 x -3 4 44 Transformation of Linear Variables y1 b11 x1 b12 x2 y2 b21 x1 b22 x2 y1 b11 b12 x1 y b b x 2 21 22 2 y = Bx 45 Transformation Continuation z1 a11 y1 a12 y2 z2 a21 y1 a22 y2 z1 a11 a12 y1 z a a y 2 21 22 2 z = Ay 46 Transformation Continuation z = Ay y = Bx z = ABx = Cx C = AB 47 Example 2-19. For the system of equations provided below, determine the z values in terms of the x values. y1 2 x1 3x2 y2 4 x1 2 x2 z1 5 y1 2 y2 z2 4 y1 3 y2 48 Example 2-19. Continuation. y1 2 -3 x1 y 4 -2 x 2 2 z1 5 -2 y1 z 4 3 y 2 2 49 Example 2-19. Continuation. z1 5 -2 2 -3 x1 z 4 3 4 -2 x 2 2 z1 2 -11 x1 z 20 -18 x 2 2 50