A Brief Review of Matrices and Linear Algebra
Total Page:16
File Type:pdf, Size:1020Kb
A Brief Review of Matrices and Linear Algebra Dr. Robert L. Williams II Mechanical Engineering Ohio University © 2016 Dr. Bob Productions [email protected] people.ohio.edu/williar4 This document is intended as a reference guide to help students review matrices and linear algebra for use in kinematics, dynamics, controls, biomechanics, and robotics. The usefulness of this document extends well beyond these fields. However, it IS NOT intended to replace a textbook in this field of mathematics. 2 Table of Contents MATRIX DEFINITION ........................................................................................................................... 3 SPECIAL MATRICES ............................................................................................................................. 4 MATRIX OPERATIONS ........................................................................................................................ 5 MATRIX ADDITION .................................................................................................................................. 5 MATRIX MULTIPLICATION WITH A SCALAR ............................................................................................. 5 MATRIX MULTIPLICATION ....................................................................................................................... 6 MATRIX DETERMINANT ......................................................................................................................... 10 MATRIX INVERSION ............................................................................................................................... 12 SOLVING A SYSTEM OF LINEAR EQUATIONS ........................................................................... 15 MATRIX EXAMPLES IN MATLAB ................................................................................................... 17 3 Matrix Definition A matrix is an m x n array of numbers, where m is the number of rows and n is the number of columns. aa11 12 a 1n aa a A 21 22 2n aamm12 a mn Matrices may be used to simplify and standardize the solution of n linear equations in n unknowns (where m = n). Matrices are used in velocity, acceleration, and dynamics linear equations (matrices are not used in analytical position analysis, which requires a non-linear solution). 4 Special Matrices These are demonstrated for 3x3 matrices, but apply to all matrix sizes. aaa11 12 13 square matrix (m = n = 3) A aaa 21 22 23 aaa31 32 33 a11 00 diagonal matrix Aa 00 22 00a33 100 identity matrix I 010 3 001 aaa11 21 31 transpose matrix AaaaT (switch rows & columns) 12 22 32 aaa13 23 33 aaa11 12 13 symmetric matrix AAT aaa 12 22 23 aaa13 23 33 x1 column vector (3x1 matrix) X x2 x3 T row vector (1x3 matrix) Xxxx 123 5 Matrix Operations Matrix Addition add like terms and keep the results in place CAB cc11 12 aa 11 12 bb 11 12 abab 11 11 12 12 cc21 22 aa 21 22 bb 21 22 abab 21 21 22 22 Matrix Multiplication with a Scalar multiply each matrix term by the scalar k and keep the results in place aa11 12 kaka 11 12 kA k a21 a 22 ka 21 ka 22 6 Matrix Multiplication CAB In general, AB BA The row and column indices must line up as follows. CAB (x)(x)(x)m nm p p n That is, in a matrix multiplication product, the number of columns p in the left-hand matrix must equal the number of rows p in the right-hand matrix. If this condition is not met, the matrix multiplication is undefined and cannot be done. The size of the resulting matrix [C] is from the number of rows m of the left-hand matrix and the number of columns n of the right-hand matrix, m x n. Multiplication proceeds by multiplying like terms and adding them, along the rows of the left- hand matrix and down the columns of the right-hand matrix (use your index fingers from the left and right hands for the left-hand rows and right-hand columns, respectively). Examples: CAB aab11 12 11 aab21 22 21 ab11 11 ab 12 21 ab21 11 ab 22 21 (2x1) (2x2)(2x1 ) Note the inner indices (p = 2) must match, as stated above, and the dimension of the result is dictated by the outer indices, i.e. m x n = 2x1. For multiplying matrices of multiple columns, follow the same procedure, first using the right index finger down the first column to yield the first column of the result and then using the right index finger down the second column to yield the second column of the result; both use rows 1 and 2. 7 CAB aabb11 12 11 12 aabb21 22 21 22 ab11 11 ab 12 21 ab 11 12 ab 12 22 ab21 11 ab 22 21 ab 21 12 ab 22 22 (2x2) (2x2)(2x2 ) The inner indices (p = 2) must match and the dimension of the result is dictated by the outer indices, i.e. m x n = 2x2. Another analytical example shows non-square matrix multiplication is possible: CAB b aaa 11 11 12 13 b 21 aaa21 22 23 b31 ab11 11 ab 12 21 ab 13 31 ab21 11 ab 22 21 ab 23 31 (2x1) (2x3)(3x1 ) The inner indices (p = 3) must match and the dimension of the result is dictated by the outer indices, i.e. m x n = 2x1. 8 We conclude with two strange but legit analytical matrix multiplication examples. CAB b11 aaab 11 12 13 21 b31 ab11 11 ab 12 21 ab 13 31 (1x1) (1x3)(3x1 ) This example is the dot product between two column vectors, i.e. the dot product can be found by transposing the first vector and using matrix multiplication: T A BAB The last example is even stranger because the matrix multiplication here only involves one multiplication for each term in the result. CAB a11 abbb 21 11 12 13 a31 ab11 11 ab 11 12 ab 11 13 ab ab ab 21 11 21 12 21 13 ab31 11 ab 31 12 ab 31 13 (3x3) (3x1)(1x3 ) This happens whenever the number of columns in the left-hand matrix equals the number of rows in the right-hand matrix, and both are p = 1. 9 Numerical Matrix Multiplication Examples 78 123 A B 98 456 76 CAB 78 123 98 456 76 7 18 21 8 16 18 46 42 28 45 42 32 40 36 115 108 (2x2) (2x3)(3x2 ) DBA 78 123 98 456 76 73214402148 395469 93218402748 415875 72414302136 314457 (3x3) (3x2)(2x3 ) Note in this example that A BBA ; they are not even of the same size. 10 Matrix Determinant The determinant of a square n x n matrix is a scalar. The matrix determinant is undefined for a non-square matrix. The determinant of a square matrix A is denoted det(A) or A . The determinant notation should not be confused with the absolute-value symbol. The MATLAB function for matrix determinant is det(A). If a nonhomogeneous system of n linear equations in n unknowns is dependent, the coefficient matrix A is singular, and the determinant of matrix A is zero. In this case no unique solution exists to these equations. On the other hand, if the matrix determinant is non-zero, then the matrix is non- singular, the system of equations is independent, and a unique solution exists. The formula to calculate a 2 x 2 matrix determinant is straight-forward. aa11 12 A aa21 22 A aa11 22 aa 21 12 To calculate the determinant of 3 x 3 and larger square matrices, we can expand about any one row or column, utilizing sub-matrix determinants. Each sub-determinant is formed by crossing out the current row and its column and retaining the remaining terms as an n–1 x n–1 square matrix, each of whose determinants must also be evaluated in the process. The pivot term (the entry in the cross-out row and column) multiplies the sub-matrix determinants, and there is an alternating + / – / + / – etc. sign pattern. Here is an explicit example for a 3 x 3 matrix, expanding about the first row (all other options will yield identical results). aaa11 12 13 A aaa 21 22 23 aaa31 32 33 aa22 23 aa 21 23 aa 21 22 Aa11 a 12 a 13 aa32 33 aa 31 33 aa 31 32 aaa11()()() 22 33 aa 32 23 aaa 12 21 33 aa 31 23 aaa 13 21 32 aa 31 22 11 For a 3 x 3 matrix only, the determinant can alternatively be calculated as shown below, by copying columns 1 and 2 outside the matrix, multiplying the downward diagonals with + signs and multiplying the upward diagonals with – signs (the result is the same as in the above formula). abc ab Adefde ghk gh aek bfg cdh gec hfa kdb a()()() ek hf b kd fg c dh ge aaa11 12 13 aa 11 12 Aa 21 a 22 a 23 a 21 a 22 aaa31 32 33 aa 31 32 aaa11 22 33 aaa 12 23 31 aaa 13 21 32 aaa 31 22 13 aaa 32 23 11 aaa 33 21 12 aaa11()()() 22 33 aa 32 23 aaa 12 23 31 aa 33 21 aaa 13 21 32 aa 31 22 aaa11()( 22 33 aa 32 23 aaa 12 21 33 aa 31 231321323122)(aaa aa ) A common usage of the 3 x 3 matrix determinant is to calculate the cross product PP12 . ijkˆˆˆ pppp pppp pp 12yz 12 zy ˆˆ11yz11xzˆ 11 xy PP1211 px pyz p 1 i j k pppp12xz 12 zx pp pp 22yzpp22xz 22 xy p222x ppyz pppp12xy 12 yx 12 Matrix Inversion Since we cannot divide by a matrix, we multiply by the matrix inverse instead. Given CAB , solve for [B]. CAB A 11CAAB IB B 1 BAC Matrix [A] must be square (m = n) to invert. The following math facts must be true: 11 A AAAI where [I] is the identity matrix, the matrix 1 (ones on the diagonal and zeros everywhere else). To calculate the matrix inverse use the following expression. 1 adjoint(A ) A A where A is the determinant of [A]. T adjoint(A ) cofactor(A ) ij cofactor(A) aAij(1) ij minor minor Aij is the determinant of the submatrix of [A] with row i and column j removed. 13 For another example, given CAB , solve for [A] CAB CB11 ABB AI A 1 A CB In general the order of matrix multiplication and inversion is crucial and cannot be changed.