Introduction Vectors and Matrices Dr. TGI Fernando 1 2 Data is frequently arranged in arrays, that is, sets whose elements are indexed by one or more subscripts. Vector - one dimensional array Matrix - two dimensional array 1 Email: gishantha@dscs.sjp.ac.lk 2 URL: http://tgifernando.wordpress.com/ Vectors [1] Vectors [2] By a vector u, we mean a list of numbers, say a 1, a 2,..., a n, and such a vector is denoted by u [a 1 a 2... a n ] The numbers a i are called components or entries of u. Zero Vector (0) - If all entries of a vector are zero (i.e. a i 0 for all i), then it s called a zero vector. Equality of two vectors - Two vectors u and v are said to be equal if they have the same number of components and corresponding components are equal. E.g. 1: (a) The following are vectors where the first two have two components and the last two have three components. [3 4], [6 8], [0 0 0], [2 3 4] (b) Although the vectors [1 2 3] and [2 3 1] contain the same numbers, they are not equal since corresponding components are not equal.
Vector Operations [1] Let u and v be two arbitrary vectors with same number of components, say u [a 1 a 2... a n ] and v [b 1 b 2... b n ]. Sum - The sum of of u and v, written u + v, is the vector obtained by adding corresponding components from u and v; i.e. u + v [a 1 + b 1 a 2 + b 2... a n + b n ] Scalar Product - The scalar product (or simply product) of a scalar and the vector u, written ku, is the vector obtained by multiplying each component of u by k; i.e. ku [ka 1 ka 2... ka n ] Vector Operations [2] We also define u 1(u) and u v u + ( v) Dot Product (or Inner Product) - The dot product of the above two vectors u and v is denoted and defined by u.v a 1 b 1 + a 2 b 2 +... + a n b n Norm (or Length) - The norm of the vector u is denoted and defined by u u.u a 2 1 + a2 2 +... + a2 n Note: u 0 iff u 0; otherwise u 0. Vector Operations [3] Column Vectors Quiz 1: Let u [ 2 3 4 ] and v [ 1 5 8 ]. Find the following: (i) u + v (ii) 5u (iii) v (iv) 2u 3v (v) u.v (vi) u Sometimes a list of numbers written vertically rather than horizontally, and the list is called a column vector. In this context, the above horizontally written vectors are called row vectors. For column vectors also, the above operations can be defined analogously. E.g. 2: 4 u 5 3
Matrices [1] Matrices [2] A matrix A is a rectangular array of numbers usually presented in the form a 11 a 12... a 1n a 21 a 22... a 2n A [a ij ].... a m1 a m2... a mn The m horizontal lists of numbers are called the rows of A, and the n vertical lists of numbers its columns. a ij - ijth entry, appears in row i and column j. A matrix with m rows and n columns is called an m by n matrix, written m n. The pair m and n is called the dimension (or size) of matrix. Equality of two matrices - Two matrices A and B are equal, written A B, if they have the same size and if corresponding elements are equal. Row matrix - A matrix with only one row Column matrix - A matrix with only one column Zero matrix (0) - A matrix whose entries are all zero Matrices [3] E.g. 3: (i) A rectangular array of dimension 2 3 1 4 5 A 0 3 2 (ii) The 2 4 zero matrix 0 [ 0 0 0 ] 0 0 0 0 0 Quiz 2: Suppose that x + y 2z + t x y z t 3 7 1 5 Matrix Addition Let A [a ij ] and B [b ij ] be matrices of same size (say m n). The sum of A and B, written A + B, is the matrix obtained by adding corresponding elements from A and B. a 11 + b 11 a 12 + b 12... a 1n + b 1n a 21 + b 21 a 22 + b 22... a 2n + b 2n A + B.... a m1 + b m1 a m2 + b m2... a mn + b mn Find values of x, y, z and t.
Scalar Multiplication Examples - Matrix Addition and Scalar Multiplication Let A [a ij ] and k be a scalar. The (scalar) product of the matrix A by a scalar k, written ka, is the matrix obtained by multiplying each element of A by k. ka 11 ka 12... ka 1n ka 21 ka 22... ka 2n ka.... ka m1 ka m2... ka mn Note: We also define A ( 1)A A B A + ( B) E.g. 4: Let A 1 2 3 4 6 8 and B. Then 0 4 5 1 3 7 1 + 4 2 + 6 3 + 8 5 4 11 A + B 0 + 1 4 + ( 3) 5 + ( 7) 1 1 2 3(1) 3( 2) 3(3) 3 6 9 3A 3(0) 3(4) 3(5) 0 12 15 2(1) 3(4) 2( 2) 3(6) 2(3) 3(8) 2A 3B 2(0) 3(1) 2(4) 3( 3) 2(5) 3( 7) 10 22 18 3 17 31 Exercice - Matrix Addition Ex. 1 The quarterly sales of Jute, Cotton and Yarn for the year 2002 and 2003 are given below. Find the total quarterly sales of Jute, Cotton and Yarn for the two years. Theorems - Matrix Addition and Scalar Multiplication Theorem 1: Let A, B, C be matrices with the same size, and let k and k be scalars. Then (i) A + (B + C) (A + B) + C (ii) A + 0 0 + A A (iii) A + ( A) ( A) + A 0 (iv) A + B B + A (v) k(a + B) ka + kb (vi) (k + k )A ka + k A (vii) (kk )A k(k A) (viii) 1A A
Matrix Multiplication [1] Let A [a ik ] and B [b kj ] be matrices such that the number of columns of A is equal to the number of rows of B (say, A is an m p matrix and B is a p n matrix). Then the product AB is the m n matrix C [c ij ] whose ij-entry is obtained by multiplying the ith row of A by the jth column of B, that is, a 11... a 1p..... a i1... a ip..... a m1... a mp c ij a i1 b 1j + a i2 b 2j +... + a ip b pj p a ik b kj k1 b 11... b 1j... b 1n........................... b p1... b pj... b pn c 11... c 1n...... c ij...... c m1... c mn Matrix Multiplication [2] E.g. 5: Find AB where A Sol: 1 3 and 2 1 2 2 2 0 4. 5 2 6 2 3 Since A is 2 2 and B is 2 3, the product AB is defined and AB is 2 3 matrix. 1 3 2 0 4 AB 2 1 5 2 6 1 2 + 3 5 1 0 + 3 ( 2) 1 ( 4) + 3 6 2 2 + ( 1) 5 2 0 + ( 1) ( 2) 2 ( 4) + ( 1) 6 17 6 14 1 2 14 Exercises - Matrix Multiplication [1] Ex. 2 Find AB and BA where A 1 2 5 6 and B. 3 4 0 2 Exercises - Matrix Multiplication [2] Ex. 4 A firm produces three products A, B and C requiring the mix of three materials P, Q and R. The requirement (per unit) of each product for each material is as follows. Ex. 3 Ram, Shyam and Mohan purchased biscuits of different brands P, Q andr. Ram purchased 10 packets of P, 7 packets of Q and 3 packets of R. Shyam purchased 4 packets of P, 8 packets of Q and 10 packets of R. Mohan purchased 4 packets of P, 7 packets of Q and 8 packets of R. If brand P costs Rs 4, Q costs Rs 5 and R costs Rs 6 each, then using matrix operation, find the amount of money spent by these persons individually. Using matrix notations, find (i) The total requirement of each material if the firm produces 100 units of each product. (ii) The per unit cost of production of each product if the per unit cost of materialsp, Q and R is Rs 5, Rs 10 and Rs 5 respectively. (iii) The total cost of production if the firm produces 200 units of each product.
Theorem Theorem 2: Let A, B, C be matrices. Then, whenever the products and sums are defined: (i) (AB)C A(BC) (Associative Law) (ii) A(B + C) AB + AC (Left Distributive Law) (iii) (B + C)A BA + CA (Right Distributive Law) (iv) k(ab) (ka)b A(kB), where k is a scalar. Matrix Multiplication and System of Linear Equations Any system S of linear equations is equivalent to the matrix equation Ax b where A is the matrix consisting of the coefcients, x is the column vector of unknowns, and b is the column vector of constants. E.g. 6: The system of linear equations is equivalent to x + 2y 3z 4 5x 6y + 8z 9 x 1 2 3 y 4 5 6 8 9 }{{} z }{{} A }{{} b x Transpose The transpose of a matrix A, written A T, is the matrix obtained by writing the rows of A, in order, as columns. E.g. 7: Note: T 1 4 1 2 3 2 5 4 5 6 3 6 1 T 1 3 5 3 5 (i) If A is n m, then A T is m n. (ii) If B [b ij ] is the transpose of A [a ij ], then b ij a ji for all i and j. Square Matrices A matrix with the same number of rows as columns is called a square matrix. A square matrix with n rows and n columns is said to be of order n, and is called an n-square matrix. Main diagonal (or Diagonal) - of an n-square matrix A [a ij ] consists of the elements a 11, a 22,..., a nn. Trace - the trace of a square matrix A, written tr(a), is the sum of diagonal elements, i.e. tr(a) a 11 + a 22 +... + a nn
Unit Matrices The n-square unit matrix, denoted by I n, or simply I, is the square matrix with 1 s along the diagonal and 0 s elsewhere. E.g. 8: Note: For any matrix A, 1 0 0 0 I 4 0 1 0 0 0 0 1 0 0 0 0 1 tr(i 4 ) 1 + 1 + 1 + 1 4 AI IA A Algebra of Square Matrices Let A be a square matrix. Then we can multiply A by itself. In fact, we can form all non-negative powers of A as follows: E.g. 9: Suppose A A 2 A 2 AA A 3 A 2 A... A n+1 A n A A 0 I (when A 0) 1 2. Then 3 4 1 2 1 2 3 4 3 4 [ 7 ] 6 9 22 Invertible (Non-singular) Matrices, Inverses Example - Inverses A square matrix A is said to be invertible (or non-singular) if there exists a matrix B such that where I is the identity matrix. AB BA I Such a matrix B is unique; it is called the inverse of A and is denoted by A 1 E.g. 10: Suppose that A 2 5 and B 1 3 3 5, then 1 2 2 5 3 5 6 5 10 + 10 1 0 AB 1 3 1 2 3 3 5 + 6 0 1 3 5 2 5 6 5 15 15 1 0 BA 1 2 1 3 2 2 5 + 6 0 1 Thus A and B are inverses. Note: It is known that AB I iff BA I; hence it is only necessary to test one product to determine whether two matrices are inverses.
Example - Application of Inverse E.g. 11: Let s solve the following system of equations 2x + 3y 80, 000 8x + 11y 3, 00, 000 This system can be written in the matrix form as follows: 2 3 x 80, 000 8 11 y 3, 00, 000 }{{}}{{}}{{} A x b Ax b A 1 (Ax) A 1 b (Multipling both sides by inverse of A) (A 1 A) x A 1 b (Associative law) }{{} I Ix A 1 b (Definition of inverse) x A 1 b Determinants [1] To each n-square matrix A [a ij ], we assign a specific number called the determinant of A and denoted by det(a) or A or a 11 a 12... a 1n a 21 a 22... a 2n.... a n1 a n2... a nn This is called the determinant of order n. Determinants [2] Example - Determinants The determinannts of order 1, 2 and 3 are defined as follows: a 11 a 11 a 11 a 12 a 21 a 22 a 11a 22 a 12 a 21 a 11 a 12 a 13 a 21 a 22 a 23 a 31 a 32 a 33 a 11 a 22 a 23 a 32 a 33 + a 12 a 23 a 21 a 33 a 31 + a 13 a 21 a 22 a 31 a 32 a 11 (a 22 a 33 a 23 a 32 ) + a 12 (a 23 a 31 a 21 a 33 )+ a 13 (a 21 a 32 a 22 a 31 ) E.g. 12: 2 1 3 4 6 1 5 1 0 2 6 1 1 0 + 1 1 4 0 5 + 3 4 6 5 1 2[(6)(0) ( 1)(1)] + 1[( 1)(5) (4)(0)] + 3[(4)(1) (6)(5)] 2[0 + 1] + 1[ 5 0] + 3[4 30] 2 5 78 81
Theorem Theorem 3: Let A and B be any n-square matrices. Then det(ab) det(a). det(b) Determinants and Inverses of 2 2 Matrices a b Let A and suppose that A ad bc 0. c d Then it can be proved that 1 A 1 a b 1 d b c d A c a In other words, when A 0, the inverse of a 2 2 matrix A is obtained as follows: (i) Interchange the elements on the main diagonal. (ii) Take the negatives of the other elements. (iii) Multiply the matrix by 1 A or, equivalently, divide each element by A. Example - Inverse of a 2 2 matrix Theorem E.g. 13: 2 3 Let A. Then A 2( 0). 4 5 A 1 1 2 [ 5 ] 3 4 2 Theorem 4: A matrix A is invertible iff it has a non-zero determinant. [ 5 2 3 2 2 1 ]
Elementary Row Operations [1] Elementary Row Operations [2] Let A be a matrix whose rows will be denoted, as respectively, by R 1, R 2,..., R m. The first non-zero element in a row R i is called the leading non-zero element. A row with all zeros is called a zero row. Thus a zero row has no leading non-zero element. The following three operations on A are called the elementary row operations: (E1) Interchange row R i and row R j. This operation will be indicated by writing: Interchange R i and R j. (E2) Multiply each element in a row R i by a non-zero constant k. This operation will be indicated by writing: Multiply R i by k. (E3) Add a multiple of one row R i to another row R j or, in other words, replace R j by the sum kr i + R j. This operation will be indicated by writing: Add kr i to R j. Elementary Row Operations [3] Row Equivalent To avoid fractions, we may perform (E2) and (E3) in one step; that is, we may apply the following operation: (E) Add a multiple of one row R i to a non-zero multiple of another row R j or, in other words, replace R j by the sum kr i + k R j where k 0. We indicate this operation by writing: Add kr i to k R j. Matrices A and B are said to be row equivalent, written A B, if matrix B can be obtained from matrix A by using elementary row operations. Note: In the row operations (E3) and (E), only row R j is actually changed.
Echelon Matrices Row Canonical Form A matrix A is called an echelon matrix, or is said to be in echelon form, if the following two conditions hold: (i) All zero rows, if any, are on the bottom of the matrix. (ii) Each leading non-zero entry is to the right of the leading non-zero entry in the preceding row. A matrix A is said to be in row canonical form if it has the following two additional properties: (i) Each leading non-zero entry is 1. (ii) Each leading non-zero entry is the only non-zero entry in its column. Note: The zero matrix 0, for any number of rows or columns, is a special example of a matrix in row canonical form. The n-square identity matrix I n is another example of a matrix in row canonical form. Examples - Row Canonical Form [1] Examples - Row Canonical Form [2] E.g. 14: Consider the following echelon matrices whose leading non-zero entries have been colored in red: 2 3 2 0 4 5 6 A 1 0 0 1 1 3 2 0 1 2 3 0 0 0 0 0 6 2 A 2 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 3 0 0 4 2 4 7 A 3 0 0 0 1 0 3 A 4 0 5 8 2 0 0 6 (i) A 1 is not in row canonical form since some leading non-zero entries are not 1. (ii) A 2 is not in row canonical form since the third column contains a leading non-zero entry and another non-zero entry. (iii) A 3 is in row canonical form. (iv) A 4 is not in row canonical form since all of its leading non-zero entries are not 1.
Triangular Form Gaussian Elimination in Matrix Form A square matrix A is said to be in triangular form if its diagonal entries a 11, a 22,..., a nn are the leading non-zero entries. E.g. 15: form. Quiz 3: The square matrix A 4 in E.g. 14 is in the triangular Is the identity matrix I in the triangular form? Consider any matrix A. (i) First transform the matrix A into an echelon form using elementary row operations. (ii) Transform the echelon matrix into a matrix in row canonical form. Example - Gausian Elimination [1] E.g. 16: Find the row canonical form of A 2 4 4 6 10 3 6 6 9 13 Sol: First, reduce the matrix A into echelon form: 2 4 4 6 10 R 2R 2 2R 1 0 0 2 4 6 3 6 6 9 13 3 6 6 9 13 0 0 2 4 6 R 3R 3 3R 1 0 0 2 4 6 3 6 6 9 13 0 0 3 6 7 0 0 2 4 6 R 3R 3 3 2 R 2 0 0 2 4 6 0 0 3 6 7 0 0 0 0 2 Example - Gausian Elimination [2] Next reduce the echelon form matrix into canonical form: 0 0 2 4 6 R 3 1 2 R 3 0 0 2 4 6 0 0 0 0 2 0 0 2 4 6 R 2R 2 6R 3 0 0 2 4 0 1 2 3 1 0 0 0 2 4 0 R 1R 1 2R 3 0 0 2 4 0
Example - Gausian Elimination [3] Theorem Next reduce the echelon form matrix into canonical form: (Cont.) 1 2 3 1 0 1 2 3 1 0 0 0 2 4 0 R 2 1 2 R 2 0 0 1 2 0 1 2 3 1 0 1 2 0 7 0 0 0 1 2 0 R 1R 1 +3R 2 0 0 1 2 0 Theorem 5: Any matrix A is row equivalent to a unique matrix in row canonical form. Inverse of an n n Matrix Let A be an n n matrix. To find the inverse A 1 of A apply the following steps: Step 1. Form the n 2n matrix M [A, I]; i.e. A is in the left of M and the identity matrix I is in the right half of M. Step 2. Row reduce M to an echelon form. (i) If the process generates a zero row in the A-half of M, then stop (A has no inverse). (ii) Otherwise, the A-half is now in triangular form. Step 3. Further row reduce M to the row canonical form M [I, B] where I has replaced A in the left half of M. Step 4. Set A 1 B, where B is the matrix that is now in the right half of M. Exercise - Inverse of a Matrix Ex. 5 Find the inverse of 1 0 2 A 2 1 3 4 1 8 Help: Take M as 1 0 2 1 0 0 M 2 1 3 0 1 0 4 1 8 0 0 1
Matrix Solution of a System of Linear Equations Exercise - Solution of a System of Linear Equations Consider the system of linear equations Ax b with the augmented matrix M [A b]. The system is solved by applying the above Gaussian elimination algorithm to M as follows. Step 1. (Reduction): Reduce the augmented matrix M to echelon form. If a row of the form (0, 0,..., 0, b), with b 0, appears, then stop. The system does not have a solution. Step 2. (Back-Substitution): Further reduce the augmented matrix M to its row canonical form. The unique solution of the system or, when the solution is not unique, the free variable form of the solution is easily obtained from the row canonical form of M. Ex. 6 Solve the following system of equations: x + 2y + z 3 2x + 5y z 4 3x 2y z 5