FACULTY OF ENGINEERING, COMPUTING AND MATHEMATICS CITS2401 Computer Analysis & Visualisation SCHOOL OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING Topic 7 Matrix Algebra Material from MATLAB for Engineers, Moore, Chapters 10 Additional material by Peter Kovesi and Wei Liu
Objectives After this lecture you should be able to: Perform the basic operations of matrix algebra Solve simultaneous equations using MATLAB matrix operations Use some of MATLAB s special matrices Use some MATLAB matrix functions
The difference between an array and a matrix Most engineers use the two terms interchangeably The only time you need to be concerned about the difference is when you perform matrix algebra calculations Arrays: Technically an array is an orderly grouping of information Arrays can contain numeric information, but they can also contain character data, symbolic data etc. Matrices: The technical definition of a matrix is a two-dimensional numeric array used in linear algebra Not even all numeric arrays can precisely be called matrices - only those upon which you intend to perform linear transformations meet the strict definition of a matrix.
Matrix Operations and Functions Matrix algebra is used extensively in engineering applications Matrix algebra is different from the array calculations we have performed thus far
Array Operators A.* B multiplies each element in array A times the corresponding element in array B A./B divides each element in array A by the corresponding element in array B A.^B raises each element in array A to the power in the corresponding element of array B A+B adds each element in array A to the corresponding element in array B A-B subtracts each element in array A from the corresponding element in array B
Operators used in Matrix Mathematics Transpose Multiplication Division Exponentiation Left Division Some Matrix Algebra functions Dot products Cross products Inverse Determinants
Transpose In mathematics texts you will often see the transpose indicated with superscript T A T The MATLAB syntax for the transpose is A'
!!!! " # $ $ $ $ % & = 12 11 10 9 8 7 6 5 4 3 2 1 A!!! " # $ $ $ % & = 12 9 6 3 11 8 5 2 10 7 4 1 T A The transpose switches the rows and columns
Using the transpose with complex numbers When used with complex numbers, the transpose operator returns the complex conjugate. The complex conjugate of a+bi is a-bi
Complex Conjugate Complex numbers have a real part, which is a normal number, and an imaginary part which is a number multiplied by i, the square root of -1. Given a complex number a + bi it s complex conjugate is a bi. This number has many of the same algebraic properties as a+ bi. Given a matrix of complex numbers, the conjugate transpose generalizes many of the properties of a complex conjugate.
Dot Products The dot product is sometimes called the scalar product the sum of the results when you multiply two vectors together, element by element. Equivalent statements
Example Calculating the Centre of mass (centre of gravity) Finding the centre of mass of a structure is important in a number of engineering applications The location of the center of mass can be calculated by dividing the system up into small components. xm = x 1 m 1 + x 2 m 2 + x 3 m 3 + etc... ym = y 1 m 1 + y 2 m 2 + y 3 m 3 + etc... zm = z 1 m 1 + z 2 m 2 + z 3 m 3 + etc...
In a rectangular coordinate system x, y, and z are the coordinates of the center of mass m is the total mass of the system x1, x2, and x3 etc are the x coordinates of each system component y1, y2, and y3 etc are the y coordinates of each system component z1, z2, and z3 etc are the z coordinates of each system component m1, m2, and m3 etc are the mass of each system component
Example Calculating the Center of mass 1D two mass example x = x 1 m 1 + x 2 m 2 m where m = m 1 + m 2 x=0 m 1 x=x 1 m 2 x=x 2
In this example We ll find the center of gravity of a small collection of the components used in a complex space vehicle Item x, meters y, meters z meters Mass Bolt 0.1 2 3 3.50 gram screw 1 1 1 1.50 gram nut 1.5 0.2 0.5 0.79 gram bracket 2 2 4 1.75 gram Formulate the problem using a dot product
Input and Output Input Location of each component in an x-y-z coordinate system in meters Mass of each component, in grams Output Location of the centre of mass
Hand Example Find the x coordinate of the centre of mass Item x, meters Mass, gram x * m, gram meters Bolt 0.1 x 3.50 = 0.35 screw 1 x 1.50 = 1.50 nut 1.5 x 0.79 = 1.1850 bracket 2 x 1.75 = 3.5 sum 7.54 6.535
We know that The x coordinate is equal to So x x = 4 x i m i i=1 m Total = =6.535/7.54 = 0.8667 meters 4 x i m i i=1 4 m i i=1 This is a dot product
We could use a plot to evaluate our results z-axis 4 3 2 1 Center of Gravity Center of Gravity This plot was enhanced using the interactive plotting tools 0 2 1 1 2 y-axis 0 0 x-axis
Matrix Multiplication Similar to a dot product Matrix multiplication results in an array where each element is a dot product. In general, the results are found by taking the dot product of each row in matrix A with each column in Matrix B
C i, j = N k=1 A i,k B k, j
Because matrix multiplication is a series of dot products the number of columns in matrix A must equal the number of rows in matrix B For an m x n matrix multiplied by an n x p matrix These dimensions must match m x n n x p The resulting matrix will have these dimensions
Matrix multiplication as a function
We could use matrix multiplication to solve the previous problem (centre of mass) in a single step
Matrix Powers Raising a matrix to a power is equivalent to multiplying it times itself the requisite number of times A 2 is the same as A*A A 3 is the same as A*A*A Raising a matrix to a power requires it to have the same number of rows and columns These dimensions must match n x n n x n The resulting matrix will have these dimensions
Matrix Inverse The inverse of a matrix A is the matrix that when multiplied by A, returns the identity matrix. MATLAB offers two approaches The matrix inverse function inv(a) Raising a matrix to the -1 power A -1
Equivalent approaches to finding the inverse of a matrix A matrix times its inverse is the identity matrix
Not all matrices have an inverse Called Singular Ill-conditioned matrices Attempting to take the inverse of a singular matrix results in an error statement The condition number of a matrix measures how close it is to being singular. The function cond(a) measures how sensitive the system of linear equations represented by the matrix A is to errors.
Determinants Related to the matrix inverse If the determinant is equal to 0, the matrix does not have an inverse The MATLAB function to find a determinant is det(a)
Cross Products sometimes called vector products the result of a cross product is a vector always at right angles (normal) to the plane defined by the two input vectors Othogonality Commonly found in equations of mechanics (e.g. fluid mechanics) and electomagnetics (i.e. Maxwell s equations, Lorentz law)
Consider two vectors A = A x i + Ay j + Az k B = B x i + By j + Bz k The cross product is equal to A B = (A y * B z A z * B y ) i + (A z * B x A x * B z ) j + (A x B y A y B x ) k
Cross Products are Widely Used Cross products find wide use in statics, dynamics, fluid mechanics and electrical engineering problems
Solutions to Systems of Linear Equations 3x +2y z = 10 x +3y +2z = 5 x y z = 1 Three variables and three equations should have a solution. We can solve these systems by subtracting one equation from another until we manage to eliminate all but one variable. This is a time consuming process and can lead to large errors if the matrix has a high condition number.
Using Matrix Nomenclature " $ A = $ $ # 3 2 1 1 3 2 1 1 1 %! ' # ' X = # ' # & " x y z $ " & $ & B = $ & $ % # 10 5 1 % ' ' ' & and AX=B
We can solve this problem using the matrix inverse approach This approach is easy to understand, but its not the most efficient computationally
Matrix left division Matrix left division: A\B is a more efficient alternative. It also has less round off error. A related function are rref(a) for calculating the reduced row echelon form of A. Matrix left division uses Gaussian elimination, which is much more efficient, and less prone to round-off error
Linear Transformations Matrix multiplication can be visualized as a continuous linear transformation of a space.! # # " y 1 y 2 $! & & = # A 11 A 12 # % " A 21 A 22 $! &# &# %" Given a two dimensional space, we can multiply every point in that space by a 2x2 matrix. This maps every point to a new point. Common transformations include rotations about the origin, scaling one or more dimensions, or change of basis. x 1 x 2 $ & & % x y
Eigenvectors Given a linear transformation, Eigenvectors are vectors that are only transformed by a scalar factor.! λ# # " x 1 x 2 $! & & = # A 11 A 12 # % " A 21 A 22 $! &# &# %" x 1 x 2 $ & & % The corresponding scalar factor λ for each Eigenvector is called an Eigenvalue. A non-singular 2x2 matrix will always have two Eigenvectors, although they may be complex vectors, as is the case for rotations.
Examples:
A script to display linear transformations
Examples: