HESC686 Mathematics and Signal Processing for Biomechanics Introduction to matrices Matrix = 2-D array. Matrices are, among other things, shorthand representations of systems of linear equations. We can use matrix notation to represent and solve the system of linear equations from the previous lecture: x–y+z=0 2x - 3y + 4z = -2 -2x – y + z = 7 This can be written with matrices as follows: 1 −1 1 𝑥 0 [ 2 −3 4] [𝑦] = [−2] −2 −1 1 𝑧 7 once we know the rules for multiplying a matrix times a column vector to get another column vector. The matrix equation above can be written 𝑨𝒙 = 𝒃 where 𝑥 1 −1 1 0 𝑨 = [ 2 −3 4] , 𝒙 = [𝑦] , 𝒃 = [−2] 𝑧 −2 −1 1 7 We can solve this system of 3 equations and 3 unknowns using Matlab. First define the constants A (a matrix) and b (a column vector) in Matlab: >> A=[1 -1 1; 2 -3 4; -2 -1 1] >> b=[0; -2; 7] Then solve the system by defining an augmented matrix (Aaug) and using Matlab’s “rowreduction echelon formula” function (rref) to find x: >> Aaug=[A b] >> x=rref(Aaug) At this point, the above method may seem mysterious. In the next lecture we will see another way to solve the system (i.e. another way to find x) which will give more insight and make more sense, but first we must learn more about working with matrices. Matrix basics Dimensions are given as rows (first), columns (second). m rows, n columns is “m by n” Square matrix has equal number of rows and columns. One-by-n matrix = row vector; n-by-one matrix = column vector. Matrix elements Notation: aij = element in row i, column j. Diagonal elements = aii. Equality of matrices Two matrices are equal if they have same dimensions and all elements are the same. Matrix arithmetic Matrix addition Add corresponding elements; matrix dimensions must match. Commutative: A+B=B+A Associative: (A+B)+C = A+(B+C) Zero matrix: all elements = 0. A + 0 = 0 + A = A Matrix subtraction: like addition. Multiplication (or division) by a scalar Multiply (or divide) each element by same scalar. Note cA = Ac . Matrix multiplication Am×n Bn×ℓ = Cm× ℓ where the subscript “m×n” indicates that matrix A has m rows and n columns, etc. The element cij, in row i, column j of the resulting matrix C, is given by cij = ai1b1j + ai2b2j + … + ainbnj = ∑ 𝑛 𝑘=1 aik bkj 1 2 5 6 ),B = ( ) , C = AB =? 3 4 7 8 Note that number of columns in A must equal the number of rows in B for matrix multiplication (AB) to work. 1 0 Identity matrix: 𝐼2 = ( ). AI = IA = A . 0 1 Matrix multiplication is not commutative. Use Matlab to compare D=BA to C=AB. >>A=[1 2;3 4]; >>B=[5 6;7 8]; >>C=A*B, D=B*A Matrix division This is complicated. We will return to this topic later. Example: 𝐴 = ( We can use a matrix and vector to represent a linear system with n equations and n unknowns. (See also the example at the start of this lecture.) In this example, A is an n-by-n matrix and x and b are coulmn vectors of length n: 𝑨𝒙 = 𝒃 𝑥 𝑦 where A is an n-by-n matrix and x and b are coulmn vectors of length n, with 𝐱 = ( ) . 𝑧 Copyright © 2010 William C. Rose