In today’s lesson, we will be covering the following topics:
1. Concatenating Arrays
2. Finding Inverse and Determinant of a Matrix
3. Reduced Row Echelon Form of a Matrix
4. Special Matrices
5. Matrix Generators
VIDEO COMING SOON!
Concatenating Arrays
To add (also called append) a row/column/number to an array, we need to concatenate arrays. To do that, you need two arrays you want to combine. Then enter the variable names of the arrays into square brackets, and they will be combined.
Check out these examples below: In this first example, I created vector A, and wanted to add the number 5 at the end of it. I then created a variable B and set it equal to 5. I used [A B] to combine these, and got an output vector of [1 2 3 4 5] which was what I wanted:
In this second example, I have concatenated two matrices together to end up with a large output matrix. By default, MATLAB attaches the matrices side by side.
Finding Inverse and Determinant of a Matrix
There are many different operations that can be done on a matrix. These include finding the inverse and the determinant. The inverse is like finding the reciprocal of a number in math, but now it’s with a matrix. The determinant is a value that helps to find the inverse of a matrix, and also tells is useful things about a matrix with regards to other mathematical concepts. The math behind both of these is explored more in-depth in the Linear Algebra course, so check that out for more info!
The inverse uses the inv(A) command, and the determinant uses the det(A) command, where A is the matrix you want to do the operation on. Note that the matrix must be a square matrix (eg. 3×3, 4×4, etc)
Take a look at these examples. I have created a matrix A, then taken the inverse and the determinant of it:
Reduced Row Echelon Form of a Matrix
MATLAB will find the Reduced Row Echelon Form (RREF) of a matrix, so you don’t have to go through all the steps. Here is a matrix A:
To find the RREF of the matrix A, use rref(A):
Here is the output matrix. I won’t go through how to solve for the unknown variables by transforming this matrix back into a system of equations, because that is a separate Linear Algebra lesson. For our purposes, I am just teaching the syntax and what it does!:
Special Matrices
MATLAB has built-in special matrices, as shown in the table below. These matrices have special properties that can be used for testing algorithms.
Matrix Generators
Sometimes, you will need to create specific matrices. There are certain commands that will create specific elementary matrices – these include matrices of all 1’s, of all 0’s, or the identity matrix (the identity matrix is also a topic where the math is explored in the Linear Algebra course) and more. Take a look at this table below, that sums up elementary matrices. Wherever it says (m,n) needs to be replaced by numbers on how many rows (m) and columns (n) you’d like. For the diag(A) command, replace A with the name of your array.
Let’s try creating some of these. I’ve done some examples below, creating matrices using the commands rand, ones, eye, and zeros.
Type in doc elmat for a full list of elementary functions, and this page will pop up: