• Nem Talált Eredményt

The Inverse of a Matrix and its Calculation

2.5 Matrices

2.5.3 The Inverse of a Matrix and its Calculation

A system of linear equations can be written in a form Ax=b by Theorem 2.5.7, whereA is the coefficient matrix andb is the vector whose coordinates are the constants on the right hand sides of the equations. As formally there is a matrix multiplication on the left hand side, it seems a natural question if there is an analogue of the division for matrices, since in that case we could hope for a solution by "dividing both sides byA". It turns out that the answer for this question is (at least in partly) positive. This means that in some cases we have this analogue. To understand the following notion correctly we note that the division by a real number a is nothing else than the multiplication by its reciprocal 1/a=a−1. Now we introduce the corresponding notion for matrices (and use the latter notation to emphasize the similarity):

Definition 2.5.4. Assume that A∈ Rn×n, then the matrix X ∈Rn×n is called the inverse of A if AX =In =XA holds. In this case we use the notation X =A−1.

It is important part of the definition that the inverse is defined only for a square matrix.

Also, if it exists, then it is unique. Indeed, ifXA=I =AX andY A =I =AY hold for the matrices X and Y, then

X =XI =X(AY) = (XA)Y =IY =Y

by Proposition 2.5.4 and by the associativity of the matrix multiplication. So the notation A−1 is justified by the uniqueness, and from now on we can talk aboutthe inverse of a matrix - at least if it exists. It is easy to see that there are matrices whose inverse exists, for example I−1 =I by Proposition 2.5.4. Unfortunately this is not always the case, but the next theorem gives a complete answer for this question:

Theorem 2.5.10. The matrix A∈Rn×n has an inverse if and only if detA 6= 0.

Proof. Assume first thatA−1 exists. It follows easily from the definition of the determinant (or by part (ii) of Theorem 2.4.2) that detIn = 1 for every n. Then by Theorem 2.5.5 we have1 = detIn= det(AA−1) = detA·detA−1, and hencedetA6= 0 must hold.

For the other direction we need the following lemma:

Lemma 2.5.11. If A ∈ Rn×n and detA 6= 0, then there exists a unique matrix X ∈ Rn×n for which AX =In holds.

Proof. IfAX =In holds, then of course X must be of size n×n. So let x1, . . . , xn ∈Rn be the columns of the matrix X. Observe that the ith column of AX is Axi by the definition of the matrix multiplication. Hence the equation AX =In holds if and only if the equation Axi =ei holds for every1≤i≤n, where e1, e2, . . . , en are the columns of In, i.e. the vectors of the standard basis of Rn (see page 46). Since detA6= 0 by our assumption, each of these equations has a unique solution by Theorem 2.4.6, and the statement follows.

Now we return to the proof of the theorem. By the lemma there is a unique matrix X for whichAX =I holds. We will show that in this caseXA =I holds as well. By Theorem 2.5.5 we have1 = detI = det(AX) = detA·detX, sodetX 6= 0holds and hence the lemma above is applicable forX as well. Thus, there is a unique matrixY for whichXY =I holds.

Now Proposition 2.5.4 and the associativity of the matrix multiplication give Y =IY = (AX)Y =A(XY) =AI =A,

henceXA=I and the theorem follows.

Now if a system of linear equations if given by the matrix equation Ax = b, where A∈Rn×n(which means that the number of equations is the same as the number of variables), and detA6= 0 also holds, then we can multiply the equation by A−1 from the left to obtain (7) x=Inx= (A−1A)x=A−1(Ax) =A−1b,

so the unique solution of the system is A−1b. This means that the system can be solved by a matrix multiplication if the matrix A−1 is known. But observe that the proof above gives a method also for the computation of the inverse (if detA 6= 0). By its last paragraph it is enough to determine the matrix X for which AX = I holds, it will be automatically the

inverse of A. By the proof of Lemma 2.5.11 this can be done by solving the systems given byAx=ei for every 1≤i≤n using Gaussian elimination (for example).

An advantage of this method is that it is not necessary to run the Gaussian elimination n times, the systems can be solved simultaneously. Indeed, the coefficient matrices of the systems agree, so the algorithm makes the same steps in all cases, we only have to keep track of the changes of all vectors on the right hand sides of the equations. That is, we write down the matrix (A|e1e2 . . . en) and run the Gaussian elimination for this matrix (note that the steps are determined only by the coefficient matrixA). If the determinant is 0, then at some point we get 0 in the main diagonal so that all the entries in its column are 0 below it and we can stop (just like in line 16of the algorithm for the calculation of the determinant, see page 67). Otherwise, after the algorithm stops, we obtain the reduced row echelon form on the left side of the vertical line, which is the matrix In in this case. So the result will be of the form (In|x1 . . . xn) where xi is the solution of the system Ax =ei, that is, on the right side of the line we get the inverse of A.

We demonstrate this method by an example. Let us calculate the inverse of the matrix A=

We are going to run the Gaussian elimination for the matrix(A|I3):

The leading coefficient in the first row is already 1 in the beginning, so in the first step we eliminate the non-zero elements below it: we add the first row to the second one and subtract 2 times the first row from the third one. After these steps the second entry of the second row is zero, but we can swap the second and the third row to obtain a non-zero entry in the main diagonal:

The arising matrix is already of row echelon form, so we turn to the second phase of the elimination. We eliminate the non-zero entries above the leading coefficient in the last row by adding 2 times the last row to the second one and subtracting 7 times the last row from the first one. Finally, we add3 times the second row to the first one:

At this point the algorithm stops and the columns on the right side of the vertical line form the inverse of A:

Now assume that we want to solve the system x1−3x2+ 7x3 =p,

−x1+3x2− 6x3 =q, 2x1−5x2+12x3 =r.

This is equivalent to the equationAx =b whereA is the matrix above and b= (p, q, r)T. As detA6= 0 and hence its inverse exists, we get by (7) that

x=A−1b =

This algorithm above works well in practice, but now we also give a formula for the inverse which is often useful in theoretical arguments. IfA∈Rn×n, then letAˆ∈Rn×nbe the matrix whose entryˆai,j in theith row and in thejth column is the cofactorCj,iassigned to the entry aj,i of A (given in Definition 2.4.5). Note that the indeces i, j are swapped in the definition of ˆai,j. Then Theorem 2.4.7 and Corollary 2.4.8 together give that

(8) AAˆ=

In general it is rather tiresome to calculate Aˆbased on its definition, but for n = 2 it is in fact very easy, since the minors of the matrix are1×1determinants whose values are just their single entry. So if

whose determinant (given explicitly in (5)) is non-zero, then

(10) A−1 = 1

We can use the theorem above to give an exact formula for the unique solution of a system Ax=b, whereA∈Rn×n and detA6= 0. As we have seen in (7), this is

A−1b = 1 detA

Ab,ˆ so the value of the variable xi is

1

If Bi is the matrix which is obtained from A when replacing its ith column by b, then the latter sum is just the determinant ofBi expanded along the ith column, so we have

Theorem 2.5.13 (Cramer’s rule). Assume that the system of linear equations is given by Ax=b, where A∈Rn×n and detA6= 0. Then the unique solution of the system is

xi = detBi

detA (1≤i≤n),

where Bi is the matrix obtained from A when replacing its ith column by the vector b.

As in the case of Theorem 2.5.12 we have to warn the reader that this formula is not practical for the calculation of the solution in general. But for n = 2 it is simple enough to take a closer look at it. So if we have the system

a1,1x1+a1,2x2 =b1, a2,1x1+a2,2x2 =b2, then

A=

a1,1 a1,2 a2,1 a2,2

, B1 =

b1 a1,2 b2 a2,2

, B2 =

a1,1 b1 a2,1 b2

, and if detA=a1,1a2,2−a1,2a2,1 6= 0, then the unique solution is given by

x1 = detB1

detA = a2,2b1−a1,2b2

a1,1a2,2−a1,2a2,1, x2 = detB2

detA = a1,1b2−a2,1b1 a1,1a2,2−a1,2a2,1.

Recall that these are the same formulae that were given at the beginning of Section 2.4.

Finally, we show another quick application of Theorem 2.5.12. Note that if the entries of the matrix A are rational numbers, then so are the entries of Aˆ (because its entries are determinants with rational entries multiplied by ±1, so every operation that we make by the calculation of Aˆ gives a rational result). Also, the determinant of A is rational, so (9) gives that A−1 has rational entries. In fact this follows also from the algorithm above for the calculation of the inverse. But the formula in (9) gives even more when we repeat this argument with integer entries. Namely, if the entries ofAare integers, then so are the entries of A, so we immediately getˆ

Corollary 2.5.14. Assume that A∈Rn×n and the entries of A are integers. If detA =±1, then the entries ofA−1 are also integers.

This is a basic (and very important) fact in number theory, but we do not go into that direction.