Docsity

Matrix Algebra for Beginners: Understanding Matrices, Determinants, and Inverses, Apuntes de Álgebra Lineal

Toggle sidebar
bg1
Matrix algebra for beginners, Part I
matrices, determinants, inverses
Jeremy Gunawardena
Department of Systems Biology
Harvard Medical School
200 Longwood Avenue, Cambridge, MA 02115, USA
3 January 2006
Contents
1 Introduction 1
2 Systems of linear equations 1
3 Matrices and matrix multiplication 2
4 Matrices and complex numbers 5
5 Can we use matrices to solve linear equations? 6
6 Determinants and the inverse matrix 7
7 Solving systems of linear equations 9
8 Properties of determinants 10
9 Gaussian elimination 11
1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Vista previa parcial del texto

¡Descarga Matrix Algebra for Beginners: Understanding Matrices, Determinants, and Inverses y más Apuntes en PDF de Álgebra Lineal solo en Docsity!

Matrix algebra for beginners, Part I

matrices, determinants, inverses

Jeremy Gunawardena

Department of Systems Biology

Harvard Medical School

200 Longwood Avenue, Cambridge, MA 02115, USA

[email protected]

3 January 2006

Contents

1 Introduction 1

2 Systems of linear equations 1

3 Matrices and matrix multiplication 2

4 Matrices and complex numbers 5

5 Can we use matrices to solve linear equations? 6

6 Determinants and the inverse matrix 7

7 Solving systems of linear equations 9

8 Properties of determinants 10

9 Gaussian elimination 11

1 Introduction

This is a Part I of an introduction to the matrix algebra needed for the Harvard Systems Biology 101 graduate course. Molecular systems are inherently many dimensional—there are usually many molecular players in any biological system—and linear algebra is a fundamental tool for thinking about many dimensional systems. It is also widely used in other areas of biology and science.

I will describe the main concepts needed for the course—determinants, matrix inverses, eigenvalues and eigenvectors—and try to explain where the concepts come from, why they are important and how they are used. If you know some of the material already, you may find the treatment here quite slow. There are mostly no proofs but there are worked examples in low dimensions. New concepts appear in italics when they are introduced or defined and there is an index of important items at the end. There are many textbooks on matrix algebra and you should refer to one of these for more details, if you need them.

Thanks to Matt Thomson for spotting various bugs. Any remaining errors are my responsibility. Let me know if you come across any or have any comments.

2 Systems of linear equations

Matrices first arose from trying to solve systems of linear equations. Such problems go back to the very earliest recorded instances of mathematical activity. A Babylonian tablet from around 300 BC states the following problem^1 :

There are two fields whose total area is 1800 square yards. One produces grain at the rate of 2/3 of a bushel per square yard while the other produces grain at the rate of 1/ a bushel per square yard. If the total yield is 1100 bushels, what is the size of each field?

If we let x and y stand for the areas of the two fields in square yards, then the problem amounts to saying that x + y = 1800 2 x/3 + y/ 2 = 1100.

This is a system of two linear equations in two unknowns. The linear refers to the fact that the unknown quantities appear just as x and y, not as 1/x or y^3. Equations with the latter terms are nonlinear and their study forms part of a different branch of mathematics, called algebraic geometry. Generally speaking, it is much harder to say anything about nonlinear equations. However, linear equations are a different matter: we know a great deal about them. You will, of course, have seen examples like (1) before and will know how to solve them. (So what is the answer?). Let us consider a more general problem (this is the kind of thing mathematicians love to do) in which we do not know exactly what the coefficients are (ie: 1, 2/3, 1/2, 1800, 1100):

ax + by = u cx + dy = v ,

and suppose, just to keep things simple, that none of the numbers a, b, c or d are 0. You should be able to solve this too so let us just recall how to do it. If we multiply the first equation by (c/a), which we can do because a 6 = 0, and subtract the second, we find that

(cb/a)y − dy = cu/a − v. (^1) For an informative account of the history of matrices and determinants, see http://www-groups.dcs.st-and.ac.uk/ history/HistTopics/Matrices and determinants.html.

It is conventional to use brackets (either round or square) to delineate matrices when you write them down as rectangular arrays. With our notation, A 23 = f and A 32 = h.

The first known use of the matrix idea appears in the “The Nine Chapters of the Mathematical Art”, the 3rd century BC Chinese text mentioned above. The word matrix itself was coined by the British mathematician James Joseph Sylvester in 1850. Matrices first arose from specific problems like (1). It took nearly two thousand years before mathematicians realised that they could gain an enormous amount by abstracting away from specific examples and treating matrices as objects in their own right, just as we will do here. The first fully abstract definition of a matrix was given by Sylvester’s friend and collaborator, Arthur Cayley, in his 1858 book, “A memoir on the theory of matrices”. Abstraction was a radical step at the time but became one of the key guiding principles of 20th century mathematics. Sylvester, by the way, spent a lot of time in America. In his 60s, he became Professor of Mathematics at Johns Hopkins University and founded America’s first mathematics journal, The American Journal of Mathematics.

There are a number of useful operations on matrices. Some of them are pretty obvious. For instance, you can add any two n × m matrices by simply adding the corresponding entries. We will use A + B to denote the sum of matrices formed in this way:

(A + B)ij = Aij + Bij.

Addition of matrices obeys all the formulae that you are familiar with for addition of numbers. A list of these are given in Figure 2. You can also multiply a matrix by a number by simply multiplying each entry of the matrix by the number. If λ is a number and A is an n × m matrix, then we denote the result of such multiplication by λA, where

(λA)ij = λAij. (7)

Multiplication by a number also satisfies the usual properties of number multiplication and a list of these can also be found in Figure 2. All of this should be fairly obvious and easy. What about products of matrices? You might think, at first sight, that the “obvious” product is to just multiply the corresponding entries. You can indeed define a product like this—it is called the Hadamard product—but this turns out not to be very productive mathematically. The matrix matrix product is a much stranger beast, at first sight.

If you have an n × k matrix, A, and a k × m matrix, B, then you can matrix multiply them together to form an n × m matrix denoted AB. (We sometimes use A.B for the matrix product if that helps to make formulae clearer.) The matrix product is one of the most fundamental matrix operations and it is important to understand how it works in detail. It may seem unnatural at first sight and we will learn where it comes from later but, for the moment, it is best to treat it as something new to learn and just get used to it. The first thing to remember is how the matrix dimensions work.

You can only multiply two matrices together if the number of columns of the first equals the number of rows of the second.

Note two consequences of this. Just because you can form the matrix product AB does not mean that you can form the product BA. Indeed, you should be able to see that the products AB and BA only both make sense when A and B are square matrices: they have the same number of rows as columns. (This is an early warning that reversing the order of multiplication can make a difference; see (9) below.) You can always multiply any two square matrices of the same dimension, in any order. We will mostly be working with square matrices but, as we will see in a moment, it can be helpful to use non-square matrices even when working with square ones.

To explain how matrix multiplication works, we are going to first do it in the special case when n = m = 1. In this case we have a 1 × k matrix, A, multiplied by a k × 1 matrix, B. According to

Figure 1: Matrix multiplication. A, on the left, is a n × k matrix. B, on the top, is a k × m matrix. Their product, AB, is a n × m matrix shown on the bottom right (in blue). The ij-th element of AB is given by matrix multiplying the i-th row of A by the j-th column of B according to the formula for multiplying 1 dimensional matrices in (8).

the rule for dimensions, the result should be a 1 × 1 matrix. This has just has one entry. What is the entry? You get it by multiplying corresponding terms together and adding the results:

(A 11 A 12 · · · A 1 k)

B 11

B 21

Bk 1

= (A 11 B 11 + A 12 B 21 + · · · + A 1 kBk 1 )

Once you know how to multiply one dimensional matrices, it is easy to multiply any two matrices. If A is an n × k matrix and B is a k × m matrix, then the ij-th element of AB is given by taking the i row of A, which is a 1 × k matrix, and the j-th column of B, which is a k × 1 matrix, and multiplying them together just as in (8). Schematically, this looks as shown in Figure 1. It can be helpful to arrange the matrices in this way if you are multiplying matrices by hand. You can try this out on the following example of a 2 × 3 matrix multiplied by a 3 × 2 matrix to give a 2 × 2 matrix.

( 1 2 3 2 3 1

There is one very important property of matrix multiplication that it is best to see early on. Consider the calculation below, in which two square matrices are multiplied in a different order

( 1 2 2 − 1

We see from this that

matrix multiplication is not commutative. (9)

This is one of the major differences between matrix multiplication and number multiplication. You can get yourself into all kinds of trouble if you forget it.

You might well ask where such an apparently bizarre product came from. What is the motivation behind it? That is a good question. A partial answer comes from the following observation. (We will give a more complete answer later.) Once we have matrix multiplication, we can use it to rewrite the system of equations (5) as an equation about matrices. You should be able to check that (5) is

complicated! A one-to-one correspondence between two algebraic structures, which preserves the operations on both sides, is called an isomorphism. We can as well work with either structure. As we will see later on, this can be very useful. Some of the deepest results in mathematics reveal the existence of unexpected isomorphisms.

5 Can we use matrices to solve linear equations?

After that diversion, let us get back to linear equations. If you saw the equation ax = u, where a, x and u were all numbers, you would know immediately how to solve for x. Provided a 6 = 0, you would multiply both sides of the equation by 1/a, to get x = u/a.

Perhaps we can do the same thing with matrices? (Analogy is often a powerful guide in mathematics.) It turns out that we can and that is what we are going to work through in the next few sections. Before starting, however, it helps to pause for a bit and look at what we have just done with numbers more closely. It may seem that this is a waste of time because it is so easy with numbers but we often take the familiar for granted and by looking closely we will learn some things that will help us understand what we need when we move from numbers to matrices.

The quantity 1/a is the multiplicative inverse of a. That is a long winded way of saying that its the (unique) number with the property that when multiplied by a, it gives 1. (Why is it unique?) Another way to write the multiplicative inverse is a−^1 ; it always exists, provided only that a 6 = 0. (As you know, dividing by zero is frowned upon. Why? If 0−^1 existed as a number, then we could take the equation 0 × 2 = 0 × 3, which is clearly true since both sides equal 0, and multiply through by 0−^1 , giving 2 = 3. Since this is rather embarrassing, it had better be the case that 0 has no multiplicative inverse.) Let us go through the solution of the simple equation ax = u again using the notation a−^1 and this time I will be careful with the order of multiplication. If we multiply the left hand side by a−^1 we get a−^1 (ax) = (a−^1 a)x = 1x = x ,

while if we multiply the right hand side we get just

a−^1 u.

Hence, x = a−^1 u. Notice that there are couple of things going on behind the scenes. We needed to use the property that multiplication of numbers is associative (in other words, a(bc) = (ab)c) and that multiplying any number by 1 leaves it unchanged.

If we want to use the same kind of reasoning for the matrix equation (11), we shall have to answer three questions.

  1. What is the matrix equivalent of the number 1?
  2. Is matrix multiplication associative?
  3. Does a matrix have a multiplicative inverse?

If we can find a satisfactory answer to all of these, then we can solve the matrix equation (11) just as we did the number equation ax = u.

From this point, we are mostly going to deal with square matrices. Remember that we can always multiply two square matrices of the same dimension.

The matrix equivalent of the number 1 is the called the identity matrix. The n × n identity matrix is denoted In but we often simplify this to just I when the dimension is clear from the context. All

the diagonal entries of In are 1 and all the off-diagonal entries are 0, so that I 4 looks like

I 4 =

You should be able to convince yourself very quickly, using the rule for matrix multiplication in Figure 1, that if A is any n × n matrix, then

A.In = In.A = A.

so that In really does behave like the number 1 for square matrices of dimension n.

Here is a little problem to test your understanding of matrix multiplication. How would you in- terchange two columns (or two rows) of a matrix just by matrix multiplication? More specif- ically, let A(i ↔ j) denote the matrix A with the columns i and j interchanged. Show that A(i ↔ j) = A.I(i ↔ j). What happens if you want to interchange rows?

The second question asks, given three n × n matrices A, B and C, whether A.(B.C) = (A.B).C? Well, you can just write down each of the products in terms of the individual entries Aij , Bij and Cij using the formula in Figure 1 and work it out. The answer turns out to be “yes”, although the calculation is quite tedious. In fact, it is just as tedious to show that associativity holds for any three matrices which can be multiplied together. If A is an n × k matrix, B a k × j matrix and C is a j × m matrix, then A.(B.C) = (A.B).C (13)

Although you can show that the matrix product is associative this way, it is not a particularly edifying proof. Mathematicians are always a bit suspicious of results that follow from long, boring calculations because they suspect they are missing something. A result as simple as (13) ought to be true for simple reasons, not complex ones. This kind of aesthetic uneasiness has often led to new mathematics. In this case, there is a simple reason why matrix multiplication is associative and it is the same reason that explains why the matrix product itself is “natural”. However, we have to change our perspective quite a bit, from algebra to geometry, to see things in this light. We will get to it in Part II.

Matrix multiplication obeys several rules that are similar to those that hold for number multiplication (with the exception, of course, of commutativity). These are listed in Figure 2.

The third question asks about the multiplicative inverse of a matrix. (From now on, we will just say “inverse”.) The inverse of the matrix A is a matrix, which we will call, by analogy with numbers, A−^1 , such that A−^1 .A = A.A−^1 = I. This only makes sense for square matrices (why?). Notice that because matrix multiplication is not commutative, it is important to make sure that both A−^1 .A and A.A−^1 give the same result. If the inverse exists, it must be unique (why?).

It turns out that the inverse matrix is closely related to the determinant. This should not really be a surprise, given what we found out above for example (2). We are going to define the inverse matrix and the determinant of a matrix through the same basic formula (16) below.

6 Determinants and the inverse matrix

You have already worked out the determinant of a 2 × 2 matrix. If we extract the 2 × 2 coefficient matrix from example (2) (^) ( a b c d

You can try writing down some of the other Laplace expansions yourself. Notice that if you pick one of the off diagonal entries of (det A)In you get a relation among the determinants of the submatrices A(ij).

Formula (17) provides a recursive algorithm for computing det(A). You can use it to work out the determinant of the 3 × 3 matrix (6). You should find it to be

a(ei − f h) − b(di − f g) + c(dh − eg). (18)

It can be fairly unhealthy calculating determinants of large matrices this way. It can sometimes be done but it can also get extremely tedious. The better method is to use some form of Gaussian elimination, which we will learn how to do in §9. The determinant has many wonderful properties, which are collected together in §8.

Formula (16) also tells us the inverse of A. If det A 6 = 0, then it should be clear from the definition of an inverse that

A−^1 =

det(A)

adj A (19)

If det(A) = 0 then A does not have a multiplicative inverse. That is another important difference between matrices and numbers. The only number which does not have a multiplicative inverse is 0 but there are lots of non-zero matrices that do not have a multiplicative inverse (try and write down a couple).

So now you know how to work out the matrix inverse. The same caveat as for determinants holds for the inverse: (19) can be helpful to understand the inverse and its properties but Gaussian elimination is a better way of computing the inverse matrix if you have to invert a large matrix by hand.

7 Solving systems of linear equations

We have now got all the ingredients we need to solve a system of n linear equations in n unknowns. Suppose that you have expressed this system, as we did in (10), in the form of a single matrix equation, Ax = u, where the unknown quantities are x 1 , x 2 , · · · , xn and the constant quantities are u 1 , u 2 , · · · , un. In this case the n × 1 matrices x and u are given by

x =

x 1 x 2 .. . xn

u =

u 1 u 2 .. . un

The first thing to do is to work out det A. You could use the Laplace expansion in (17), Gaussian elimination as in §9 or even get MATLAB to calculate it for you. If det A = 0 then the system may have no solution. (There is a lot more that could be said about this case but it takes more work and is not particularly useful for us.) If det A 6 = 0 then, you can form the inverse matrix given in (19) and follow the strategy that works for numbers by multiplying through by the inverse matrix and using associativity to simply the algebra. You should find that

x =

det A

(adj A)u. (20)

The only problem with this is the adjugate, which is quite complicated to calculate. There is a clever way of avoiding this which was worked out by the Swiss mathematician Gabriel Cramer in the 18th

century and is known as Cramer’s rule to this day. You can get a hint of the idea by going back to our bare hands solution of the 2 × 2 system in (2) and noticing that, although the denominator of the solutions (3) and (4) is the determinant, just as we would expect from (20), the numerator also looks like a determinant. The question is, of what matrix is it the determinant? Cramer found a neat answer to this. Suppose you want to know the solution for the i-th unknown, xi. Replace the

i-th column of the matrix A by the n × 1 matrix u. Let us call this matrix A i ←− u. Cramer noticed

that (in our language—he knew nothing of the adjugate) (adj A)u = det(A i ←− u). This follows from a Laplace expansion. (Can you see why?) Cramer’s rule then states that:

xi =

det(A ←−i u) det A

Let us try this out on example (2) using the old notation. If we replace the first column of A by u and the second column of A by u we get, respectively, the two 2 × 2 matrices ( u b v d

and

a u c v

Their determinants are, respectively, ud − bv and av − cu. According to Cramer’s rule, the solutions of (2) should be

x = ud − bv ad − bc

y = av − cu ad − bc

which is exactly what we found for (2). You now know about inverse matrices and how to solve systems of linear equations, at least when det A 6 = 0.

8 Properties of determinants

The most important property of the determinant is that it is a multiplicative function on matrices. In other words,

det AB = (det A)(det B) (21)

This is fairly amazing and it is something you need to remember. You should at least check the 2 × 2 case for yourself to satisfy yourself that it works. The proof in higher dimensions is one of the hardest in elementary matrix algebra. We will get a better idea of why (21) is true when we look at matrices from a geometric perspective in Part II.

Just because (21) is true, do not make the mistake of thinking that the determinant is also additive! However, it does obey several simple rules that are helpful in calculating it.

Rule (1) If matrix B is obtained from A by multiplying each entry in one column by λ (which is not the same thing as λA) then det B = λ(det A). For example,

det

λa b λc d

= λad − bλc = λ(ad − bc).

You should see from this that if A is an n × n matrix then det(λA) = λn^ det A. Also, if one column of A consists entirely of zeros, then this rule tells us that det A = 0. (Why?)

Rule (2) Although the determinant is not additive, it obeys a restricted form of additivity on individual rows or columns. If u and v are any two n × 1 matrices, then, recalling the notation we

used in §7, det(A i ←− (u + v)) = det(A i ←− u) + det(A i ←− v). For example,

det

a u 1 + v 1 c u 2 + v 2

= a(u 2 + v 2 ) − (u 1 + v 1 )c = (au 2 − u 1 c) + (av 2 − v 1 c).

Step 1 Take the next column. If Akk = 0 look at all the entries in column k lying below Akk. If all of them are zero then column k is already in upper triangular form and you should move to the next column. If there is some non-zero entry on row l, where l > k, then interchange rows k and l. (We will keep calling the matrix that results from changes like this A, although, of course, it is no longer the matrix A we started with.) A now has Akk 6 = 0, so we can proceed to the next step.

Step 2 Use Akk to triangularise column k. Suppose there is some non-zero entry in column k lying below Akk. That is, for some l > k, Alk 6 = 0. We are going to change row l by subtracting from it row k multiplied through by Alk/Akk. (Multiplying through by a number means that each entry on row k is multiplied by the number.) The effect is to make Alk = 0. (If you think about it for a moment, you will see that this is exactly the trick that we used to solve the linear equations in (2).) Proceed in this way until all the entries lying below Akk are zero. Column k is now in upper triangular form and you can proceed to the next column.

At the end of the procedure, A will be in upper triangular form. Why is that useful? Well, the two operations that we have repeatedly used are interchanging two rows and adding a multiple of one row to another. Both of these operations are equivalent to pre-multiplying A by a suitable matrix. We worked out the matrix needed for the interchange operation in §8. At least, we worked it out for columns, while here we are doing it for rows. The principle is identical but instead of post- multiplying A, we pre-multiply A. Note that, as above, the determinant of the pre-multiplication matrix for interchanging two rows is always −1. As for the other operation, if you did the exercise at the end of the previous section then you already know that this operation does not change the determinant but let us look at it from the viewpoint of matrix multiplication. Suppose you want to add λ times row 1 to row 3 of a 4 × 4 matrix A. You should be able to see quickly that this is equivalent to pre-multiplying A by

   

λ 0 1 0 0 0 0 1

.^ (22)

This matrix is lower triangular so Rule (5) in §8 tells us that its determinant is 1. It follows that what we have done to A by Gaussian elimination is to form the matrix product W 1 W 2 · · · WpA where the matrices Wi are either interchange matrices, whose determinant is −1, or matrices like (22), whose determinant is +1. But now remember formula (21) which tell us that the determinant is a multiplicative function. If follows that the determinant of the matrix we started with is the determinant of the matrix we ended with, multiplied by (−1)u, where u is the number of times we interchanged rows. The matrix we ended with is upper triangular and we know from rule (5) in § 8 that the determinant of an upper-triangular matrix is the product of its diagonal entries. Hence, you can readily work out the determinant of A—its the determinant of the upper triangular matrix that you ended up with, up to a sign, and the sign can be worked out by keeping track of the number of times you interchanged rows in bringing A to upper triangular form.

Let us try this out on the example below. The notation should be self-explanatory. Since A 11 = 1, we do not need to interchange any rows. We first use A 11 to make A 21 = 0

 

 −R−^2 −^ ⇒−−R−^2 −−−^2 −∗R−→^1

and then use it to make A 31 = 0,

 −R−^3 −^ ⇒−−R−^3 −−−^3 ∗−R−→^1

At this point column 1 is in upper triangular form so we turn to column 2. A 22 = −1, so, once again, we do not need to do any row interchanges. Since A 32 6 = 0, we use A 22 to make it so,

 

 −R−^3 −^ ⇒−−R−^3 −−R−→^2

which leaves the matrix in upper triangular form. Since A 33 = 0, we conclude that our original matrix had a determinant of 0. You might like to check this using formula (18).

If det A 6 = 0, unlike this example, then we know that A−^1 exists. We can work out A−^1 by taking the procedure above one stage further. Assume that we have brought our matrix to upper triangular form and that all the diagonal entries are non-zero.

Step 3 Since each Akk is non-zero, we can use each in turn to set to zero all the entries lying above the diagonal. The matrix is now in diagonal form.

Step 4 Multiply each row k by 1/Akk. This brings the matrix to the identity.

What good is this? We seem to have lost the matrix we started with and be no wiser as to its inverse. To see how to recover the inverse, note that we have used an additional operation in Step 4 but this operation also amounts to pre-multiplying A by a suitable matrix. You should be able to work out that this is a simple diagonal matrix. (Note that its determinant is no longer ±1 but we no longer need that at this point.) The net result is that we have constructed the identity matrix through the series of matrix multiplications, W 1 W 2 · · · Wq A, where the Wi are either interchange matrices, lower triangular matrices of the form (22) or diagonal matrices needed for row multiplications. In other words, (W 1 W 2 · · · Wq )A = I ,

from which it follows that W 1 W 2 · · · Wq = A−^1. We were building up the inverse matrix all along. But how do we keep track of the Wi matrices? There is a very neat trick for doing this, which allows you to get away with not worrying about the Wi at all. Instead of doing the row operations on just A we do them on the n × 2 n matrix which consists of A in the first n columns and the identity matrix in the last n columns. Let us denote this matrix, in a non-standard way, by A | I, to show the two parts of it. If you now go through all the row operations in Steps 1 to 4 needed to reduce A to the identity matrix but apply them to A | I instead of just to A, the effect is equivalent to W 1 W 2 · · · Wq A | W 1 W 2 · · · Wq I (this should be clear from the rule for matrix multiplication). But, because I is the identity matrix, W 1 W 2 · · · Wq I = W 1 W 2 · · · Wq , so what we end up with in the last n columns of A | I is exactly the inverse matrix that we want.

Index

  • abstracting,
  • adjugate, 8,
  • algebraic geometry,
  • algorithm,
  • associativity,
  • complex numbers,
  • Cramer’s rule,
  • determinant, 2, 8, 10,
    • 2 × 2,
    • 3 × 3,
    • multiplicative function,
    • simple rules,
    • triangular matrix,
  • fundamental theorem of algebra,
  • Gaussian elimination, 2, 9,
  • Hadamard product,
  • inverse,
  • isomorphism,
  • Laplace expansions,
  • linear equations, 1,
  • matrix, 2,
    • dimensions,
    • identity,
    • inverse, 7, 9,
    • product, 3,
    • square,
    • triangular, 11,
  • nonlinear,
  • one-to-one correspondence,
  • recursion,
    • column vector, vector
    • row vector,