You are on page 1of 40

Introduction to matrices A matrix is a table of numbers arranged in rows and columns, with brackets (usually square) around the

outside. Here's one.

Actually it doesn't have to be numbers in there, those elements in a matrix can be letters or functions instead. The matrix provides a grid in which we can store such objects in named locations, for example in the matrix above the number 4 is in "row 2, column 1".

In this notebook you'll see that matrices are not just used to store data, however. This is because they can be added, subtracted, multiplied and generally manipulated, so that we can get at much greater information about the data and what it represents. This will become clearer as you work your way through the notebook. To start with, there's some definitions to learn, to make it easier to describe the various features of the matrices we'll encounter. An "n x m" matrix Here's the matrix we saw earlier.

This matrix has 3 rows and 3 columns. That means it's a "3 x 3" matrix. This next one has 4 rows and 2 columns. So it's a 4 x 2 matrix.

You will have noticed that we always say the number of rows first, then the number of columns second. So an n x m matrix has n rows and m columns. How would you describe this matrix?

It's a ..... Return In the particular case when n is equal to m, we say that the matrix is square. So this is a square matrix, since n=m=3:

The location of an element We can describe the location or position within the matrix of any of the elements in words, by saying which row and which column it is in. So in the matrix below, the element "-5" is in the top row, that's row 1 and in column 4.

A quicker way to describe its position is to use subscripts. Here's how. Suppose we call the matrix A. Then the element in the first row and the first column is written as A11.

In the case of the matrix above then, A11=3. And the element we were thinking of just now, element A14 is -5. As before, the first subscript refers to the row, the second to the column. What values do the following elements have? A23, A32, A13. Notice that element A23 is completely different from A32, you need to remember that the row number always comes first. Sometimes instead of A11, for example, the lower case "a11" is used, giving the following general matrix:

Return Equal matrices For two matrices to be equal, every single element in the first matrix must be equal to the corresponding element in the other matrix. So these two matrices are equal:

but these two are not:

Of course this means that if two matrices are equal, then they must have the same numbers of rows and columns as each other. So a 3x3 matrix could never be equal to a 2x4 matrix, for instance. Also remember that each element must be equal to that element in the other matrix, so it's no good if all the values are there but in different places:

Return Adding and subtracting matrices To add two matrices together, we add the corresponding elements together. That's all there is to it. So here's a straightforward example:

We add the element in row 1, column 1 in the first matrix, to the element in row 1, column 1 in the second matrix and put the result in the position row 1, column 1 in the resultant matrix. Then do the same for the other five elements. Notice that we can only add two matrices that are the same shape, since we need every element in the first matrix to have a corresponding element in the second. So we can't add a 2x3 matrix to a 3x2 matrix. We use the same idea for subtracting matrices. Here's those two matrices from above, but this time instead of adding we'll subtract the second from the first.

Now here's a few for you to practise on. In each case, first add the pairs of matrices, then subtract the second from the first. Answers

Answers

Answers Multiplying a matrix by a number Suppose we have the following matrix and we want to multiply it by 2.

Then (as with the adding and subtracting) we treat each element separately, multiplying each element by 2.

So we get the following result:

Similarly to multiply the matrix by 3, we multiply each element by 3. Similarly for any number. So we can write the more general case of multiplying that matrix by any number c, say, as:

Now we can go one step further and make our rule still more general, by using our general matrix:

If we multiply this general matrix by any number c, we get this:

So now we can multiply any matrix by any number. It's the same whether c is positive or negative, whole number, fraction or decimal, real or imaginary. It's also the same process whatever the shape of the matrix, whether it's 3x5 or 4x4 or any other combination.

So it's fairly straightforward to multiply a matrix by a number (a number is also known as a scalar by the way) but it gets a little more complicated if we want to multiply a matrix by another matrix. We'll look at that in the next section. When can we multiply two matrices together? Here's the rule (we'll see why this is the rule in a minute...): We can only multiply two matrices together if the number of columns in the first matrix is the same as the number of rows in the second matrix. So here's two matrices we can multiply together:

In that case the first matrix is 2x3 and the second matrix is 3x4. That means we can multiply them because the 3's are the same. A way to remember is to write the "shapes" next to each other as if multiplying them: 2x3x3x4. Then if the two MIDDLE numbers are the same, it's OK to multiply them. If not, it's not. Here's two that we can't multiply together:

There the first matrix is 2x2, and the second is 4x3. So if we write them together we get: "2x2x4x3" and the two middle numbers are not the same, so we can't multiply them together. Notice that the order we write the matrices is very important. We can multiply a 2x3 matrix by a 3x4 matrix, as we get 2x3x3x4, BUT if we write them the other way round, we get 3x4x2x3 and the two middle numbers are NOT equal. So even when we can multiply two matrices together, it is usually only when we write them in the right order!

How can we multiply two matrices together? OK so now we know what shape of matrices can be multiplied together, how do we actually do it? It seems quite a complicated procedure at first but after some practice you'll find you get used to it. Here's a diagram to illustrate it.

To start with, we'll concentrate on working out the first element of the result matrix, element a11.(That's the element in the first row and the first column of the result matrix.)

We need to use the first row of the first matrix and the first column of the second matrix. We work our way across that first row and at the same time down that second column, shown by the lines I've drawn in, multiplying the two elements together. The first thing to do is to multiply the 1 in the first matrix by the 3 in the second matrix. Then, moving across the top row in the first matrix and down the first column in the second matrix, we multiply the 2 by the 4. Finally we add the results of those two multiplications to get the element a11 in the result matrix. That gives 1x3+2x4=3+8=11. So the element a11 in the result matrix is 11.

The subscripts in that result element show which row and column we used to find it: we used the first row in the first matrix, that gives the first subscript 1 and we used the first column in the second matrix, that gives the second subscript 1. We'll go through all the other elements in the result matrix in the same way. Don't worry if it seems confusing now, by the time you've gone through the other 5 elements it will probably be getting clearer! So now we'll move on to the next element in the result matrix, let's calculate the element a12. Practice at multiplying two matrices together

In each case, multiply the two matrices together (in the order shown!) and then look at the answer. Answer

Answer

Answer Solving several simultaneous equations

Let's start off with 2 simultaneous linear equations:

Now as you probably know, one way to solve those two simultaneous equations, i.e. to find the values of x and y which satisfy both the equations, is to add or subtract a multiple of one equation to or from the other, in order to eliminate either x or y. Here's how we do that. We can do just the same thing with matrices, here's how..... The advantage of doing it with matrices is that when we have a larger number of simultaneous equations to solve, we can use just the same

method and it is easier to keep track of where we have got to in the calculation. So here's an example involving 3 simultaneous equations. Solving 2 simultaneous equations Here are the equations again: Now the aim is to combine the equations in such a way that we eliminate one of the variables. If we multiply the first equation by some number then we can get the coefficient of the "x" to be the same in both equations. Then we can subtract one equation from the other and the x-terms will cancel.

So let's multiply the first equation by 3, so we have "6x" in both equations: Now, as planned, we can subtract that new equation from the second equation and the x-terms cancel: Thus we are left with an equation that involves only "y", which we can therefore rearrange to see what the value of y is: Having found y, we can substitute it into either of the two original equations to find x. Let's substitute it into the first:

Rearranging that equation for x we can see the value of x: So our result is that x=11/7 and y=2/7. Return Solving 2 simultaneous equations using matrices Here are the equations again: Now we can write those two equations as a single matrix equation as follows.

You see that the matrix is just made up of the coefficients of the x's and y's. It's simply an efficient way to present the information. If you try multiplying the matrices on the left-hand side you will find that you do get the matrix on the right-hand side. Now here's how we solve that matrix equation, i.e. find the values of x and y. It's extremely similar to what we just did in the previous section! We need to use row operations to try to get zero's in that first matrix. (That's exactly equivalent to combining the two simultaneous equations to eliminate one of the variables that we just did)

So if we multiply the first row by some number then we can get the first element to be the same in both rows. Then we can subtract one row from the other and the first terms will cancel. So let's multiply the first row by 3, so we have "6" as the first element in both rows: Now, as planned, we can subtract that first row from the second row and the first elements cancel: Thus we are left with a second row that has only one non-zero element, the -14. If we now turn this back into equations, we can use that second equation to see what the value of y is:

Having found y, as before we can substitute it into either of the two original equations to find x. As before we get the result is that x=11/7 and y=2/7. Return Solving 3 simultaneous equations using matrices Here are 3 simultaneous equations:

and here they are written as a single matrix equation:

As before the matrix is just made up of the coefficients of the x's and y's and z's. Again we need to use row operations to try to get zero's in that first matrix. In particular we want to end up with this sort of picture:

Then the bottom row will tell us z, then substituting that value of z into the middle row will tell us y and finally we substitute them both into the top row to find x. A matrix of this form is called upper triangular. Here's our matrix again:

With that aim in mind, we need to multiply the first row by some number so that we can get the element in the first column to be the same in the first and third rows. Then we'll be able to subtract row(1) from row(3) and we'll have our first zero. So let's multiply the first row by 4, so we have "8" as the first element in the first and third rows:

Now, as planned, we can subtract that first row from the third row and the first terms cancel:

Next we do the same for the second row:

Now the names of the rows are getting a little confusing so let's rename them as they are now as NewRow1, NewRow2 and NewRow3. The last stage now is to turn the second element in the bottom row into zero using row 2. In this case we can simply subtract row2 from row3 as they both have -7 in the second column:

We can now use the bottom row to write down the value of z: Having found z, we can substitute it into the second equation to find y:

so Having found y and z, we can substitute them both into the first equation to find x: so We get the result is that x=37/28 and y=17/7 and z=7/2. Return

Determinants Given any matrix we can write down its determinant. Here is a general matrix and below is its determinant.

You see that the determinant is written just the same as the matrix but between two vertical lines instead of in square brackets. We can assign a particular numerical value to a determinant, unlike the matrix. We'll start with 2x2 determinants. The rule is very simple: If this is the determinant,

then to evaluate it you multiply element a11 by element a22 and subtract the product of elements a21 and a12. So the determinant is: D=(a11a22-a21a12). Here's a few examples. In each case, evaluate the determinants. Have a go first, then click on each to check your answer.

Now onto 3x3 determinants. You will already have probably seen these, when evaluating a vector cross-product. Here's a reminder of that: a cross-product determinant and how to evaluate it. And here's the method for a more general determinant. That all looks fairly complicated, so here's an example to make it clearer. Really it's quite quick! Evaluate the following determinant:

Evaluating a 3x3 determinant Here is a general 3x3 determinant:

As with the vector cross-product, the procedure is to consider each element along the top row and evaluate the associated 2x2 determinants. Here are the 2x2 determinants that we use in each case:

For each of those top-row elements, we multiply the element by its associated 2x2 determinant. So in this general case this gives us: D=a11{a22a33-a32a23} +a12{a23a31-a33a21} +a13{a21a32-a31a22} Return

You might also like