Linear Algebra Using MATLAB
Total Page:16
File Type:pdf, Size:1020Kb
Linear Algebra Using MATLAB MATH 5331 1 May 12, 2010 1Selected material from the text Linear Algebra and Differential Equations Using MATLAB by Martin Golubitsky and Michael Dellnitz Contents 1 Preliminaries 1 1.1 Vectors and Matrices . 1 1.2 MATLAB . 4 1.3 Special Kinds of Matrices . 8 1.4 The Geometry of Vector Operations . 11 2 Solving Linear Equations 18 2.1 Systems of Linear Equations and Matrices . 19 2.2 The Geometry of Low-Dimensional Solutions . 28 2.3 Gaussian Elimination . 36 2.4 Reduction to Echelon Form . 50 2.5 Linear Equations with Special Coefficients . 57 2.6 *Uniqueness of Reduced Echelon Form . 64 3 Matrices and Linearity 66 3.1 Matrix Multiplication of Vectors . 67 3.2 Matrix Mappings . 72 3.3 Linearity . 78 3.4 The Principle of Superposition . 84 i 3.5 Composition and Multiplication of Matrices . 88 3.6 Properties of Matrix Multiplication . 92 3.7 Solving Linear Systems and Inverses . 97 3.8 Determinants of 2 2 Matrices . 106 × 4 Determinants and Eigenvalues 110 4.1 Determinants . 110 4.2 Determinants, An Alternative Treatment . 124 4.3 Eigenvalues . 136 4.4 Eigenvalues and Eigenvectors . 143 4.5 *Markov Chains . 156 4.6 Appendix: Existence of Determinants . 166 5 Vector Spaces 169 5.1 Vector Spaces and Subspaces . 170 5.2 Construction of Subspaces . 177 5.3 Spanning Sets and MATLAB . 181 5.4 Linear Dependence and Linear Independence . 185 5.5 Dimension and Bases . 188 5.6 The Proof of the Main Theorem . 193 6 Linear Maps and Changes of Coordinates 200 6.1 Linear Mappings and Bases . 200 6.2 Row Rank Equals Column Rank . 207 6.3 Vectors and Matrices in Coordinates . 211 6.4 Matrices of Linear Maps on a Vector Space . 219 ii 7 Orthogonality 224 7.1 Orthonormal Bases . 224 7.2 Least Squares Approximations . 228 7.3 Least Squares Fitting of Data . 234 7.4 Symmetric Matrices . 242 7.5 Orthogonal Matrices and QR Decompositions . 246 8 Matrix Normal Forms 254 8.1 Real Diagonalizable Matrices . 254 8.2 Simple Complex Eigenvalues . 260 8.3 Multiplicity and Generalized Eigenvectors . 270 8.4 The Jordan Normal Form Theorem . 276 8.5 *Appendix: Markov Matrix Theory . 285 8.6 *Appendix: Proof of Jordan Normal Form . 288 MATLAB Commands 292 iii Chapter 1 Preliminaries The subjects of linear algebra and differential equations involve manipulating vector equa- tions. In this chapter we introduce our notation for vectors and matrices — and we intro- duce MATLAB, a computer program that is designed to perform vector manipulations in a natural way. We begin, in Section 1.1, by defining vectors and matrices, and by explaining how to add and scalar multiply vectors and matrices. In Section 1.2 we explain how to enter vectors and matrices into MATLAB, and how to perform the operations of addition and scalar multipli- cation in MATLAB. There are many special types of matrices; these types are introduced in Section 1.3. In the concluding section, we introduce the geometric interpretations of vector addition and scalar multiplication; in addition we discuss the angle between vectors through the use of the dot product of two vectors. 1.1 Vectors and Matrices In their elementary form, matrices and vectors are just lists of real numbers in different formats. An n-vector is a list of n numbers (x1,x2,...,xn). We may write this vector as a row vector as we have just done — or as a column vector x1 . . . xn The set of all (real-valued) n-vectors is denoted by Rn; so points in Rn are called vectors. The sets Rn when n is small are very familiar sets. The set R1 = R is the real number line, and the set R2 is the Cartesian plane. The set R3 consists of points or vectors in three dimensional space. 1 An m n matrix is a rectangular array of numbers with m rows and n columns. A × general 2 3 matrix has the form × a a a A = 11 12 13 . ' a21 a22 a23 ( We use the convention that matrix entries aij are indexed so that the first subscript i refers to the row while the second subscript j refers to the column. So the entry a21 refers to the matrix entry in the 2nd row, 1st column. An m n matrix A and an m! n! matrix B are equal precisely when the sizes of the × × matrices are equal (m = m! and n = n!) and when each of the corresponding entries are equal (aij = bij). There is some redundancy in the use of the terms “vector” and “matrix”. For example, a row n-vector may be thought of as a 1 n matrix, and a column n-vector may be thought × of as a n 1 matrix. There are situations where matrix notation is preferable to vector × notation and vice-versa. Addition and Scalar Multiplication of Vectors There are two basic operations on vectors: addition and scalar multiplication. Let x = (x1,...,xn) and y =(y1,...,yn)ben-vectors. Then x + y =(x1 + y1,...,xn + yn); that is, vector addition is defined as componentwise addition. Similarly, scalar multiplication is defined as componentwise multiplication. A scalar is just a number. Initially, we use the term scalar to refer to a real number — but later on we sometimes use the term scalar to refer to a complex number. Suppose r is a real number; then the multiplication of a vector by the scalar r is defined as rx =(rx1,...,rxn). Subtraction of vectors is defined simply as x y =(x y ,...,x y ). − 1 − 1 n − n Formally, subtraction of vectors may also be defined as x y = x +( 1)y. − − Division of a vector x by a scalar r is defined to be 1 x. r The standard difficulties concerning division by zero still hold. 2 Addition and Scalar Multiplication of Matrices Similarly, we add two m n matrices by adding corresponding entries, and we multiply a × scalar times a matrix by multiplying each entry of the matrix by that scalar. For example, 02 1 3 1 1 + − = − ' 46( ' 14( ' 5 10 ( and 2 4 8 16 4 − = − . ' 31( ' 12 4 ( The main restriction on adding two matrices is that the matrices must be of the same size. So you cannot add a 4 3 matrix to 6 2 matrix — even though they both have twelve × × entries. Hand Exercises In Exercises 1 – 3, let x = (2, 1, 3) and y = (1, 1, 1) and compute the given expression. − 1. x + y. 2. 2x 3y. − 3. 4x. 4. Let A be the 3 4 matrix × 2 101 − A = 347 10 . − 6 342 − n (a) For which n is a row of A a vector in R ? (b) What is the 2nd column of A? (c) Let a be the entry of A in the ith row and the jth column. What is a a ? ij 23 − 31 For each of the pairs of vectors or matrices in Exercises 5 – 9, decide whether addition of the members of the pair is possible; and, if addition is possible, perform the addition. 5. x = (2, 1) and y = (3, 1). − 6. x = (1, 2, 2) and y =( 2, 1, 4). − 7. x = (1, 2, 3) and y =( 2, 1). − 13 21 8. A = and B = . 04 1 2 ' ( ' − ( 3 210 21 9. A = 410 and B = . 1 2 000 ' − ( 21 02 In Exercises 10 – 11, let A = and B = and compute the given expression. 14 3 1 ' − ( ' − ( 10. 4A + B. 11. 2A 3B. − 1.2 MATLAB We shall use MATLAB to compute addition and scalar multiplication of vectors in two and three dimensions. This will serve the purpose of introducing some basic MATLAB commands. Entering Vectors and Vector Operations Begin a MATLAB session. We now discuss how to enter a vector into MATLAB. The syntax is straightforward; to enter the row vector x = (1, 2, 1) type1 x = [1 2 1] and MATLAB responds with x= 121 Next we show how easy it is to perform addition and scalar multiplication in MATLAB. Enter the row vector y = (2, 1, 1) by typing − y = [2 -1 1] and MATLAB responds with y= 2 -1 1 1MATLAB has several useful line editing features. We point out two here: (a) Horizontal arrow keys ( , ) move the cursor one space without deleting a character. → ← (b) Vertical arrow keys ( , ) recall previous and next command lines. ↑ ↓ 4 To add the vectors x and y, type x+y and MATLAB responds with ans = 312 This vector is easily checked to be the sum of the vectors x and y. Similarly, to perform a scalar multiplication, type 2*x which yields ans = 242 MATLAB subtracts the vector y from the vector x in the natural way. Type x-y to obtain ans = -1 3 0 We mention two points concerning the operations that we have just performed in MATLAB. (a) When entering a vector or a number, MATLAB automatically echoes what has been entered. This echoing can be suppressed by appending a semicolon to the line. For example, type z = [-1 2 3]; and MATLAB responds with a new line awaiting a new command. To see the contents of the vector z just type z and MATLAB responds with z= -1 2 3 (b) MATLAB stores in a new vector the information obtained by algebraic manipulation. Type a = 2*x - 3*y + 4*z; 5 Now type a to find a= -8 15 11 We see that MATLAB has created a new row vector a with the correct number of entries. Note: In order to use the result of a calculation later in a MATLAB session, we need to name the result of that calculation.