Computing inverses of matrices
3.01K subscribers
SUBSCRIBED
Matrix inverses are best computed by hand using a form of row reduction with a suitably augmented matrix.
00:01
hello everyone we're now in a good
00:03
position to be able to compute inverses
00:06
of larger square matrices this is a key
00:10
computational issue in linear algebra
00:12
and admittedly it gets it gets tricky or
00:16
it gets hard just because it kind of you
00:20
know the complexity of it increases
00:22
quite dramatically as the sizes of the
00:24
inverse matrices well of course these
00:26
days we have computer programs that deal
00:28
pretty efficiently with these things but
00:30
even with those you know once you get to
00:33
a thousand by thousand matrix computing
00:35
universes is highly non-trivial ok so
00:39
last time we derived the following kind
00:41
of approach to things so let's let a be
00:45
an N by n matrix which is invertible so
00:55
it does have an inverse alright so a
00:58
inverse exists and our job is to find it
01:04
now how did we do that Lester so what we
01:07
did is we looked at the system's a times
01:19
x equals e eye where the eye is the
01:25
basis vector which is all zeros except
01:29
for a single one in the 8th spot ok
01:33
otherwise its zeros ok so we consider
01:37
this system and we know that if a is
01:40
invertible than any system like this has
01:42
a unique solution so that was that our
01:45
main theorem that we talked about the
01:47
last few lectures so we know this has a
01:52
unique solution say Y I I II a times y
02:03
equals e I and then we saw that if we
02:08
create the matrix Y which is the
02:12
matrix which has these vectors y1 y2
02:16
down to yn along the columns this thing
02:23
is a right inverse for a ie a times y is
02:32
the identity matrix and furthermore and
02:36
it is also the inverse that was sort of
02:41
the main point that we derived in our
02:44
last discussion of things right that the
02:47
the right inverse if it exists ends up
02:53
being also a left inverse so this is how
02:56
we're going to get the inverse a so in
03:01
other words we're finding that a inverse
03:03
is equal to Y and this is then a
03:05
procedure for finding the inverse of the
03:07
matrix where we do things sort of
03:09
essentially sort of one column at a time
03:11
find the first column of the inverse and
03:13
then the second column and then so on
03:15
okay so we're going to illustrate that
03:17
and we'll see actually that there's a
03:19
kind of a shortcut way of doing this
03:22
sort of all the same time so let's have
03:25
a look at an example suppose a is matrix
03:29
a 2 4 1 3 ok let's try to find its
03:34
inverse with this approach ok so what
03:38
we're going to do first is we're going
03:40
to look at the Augmented system that has
03:43
a on the left and the first basis
03:46
element on the right ok so let's solve
03:49
this system ok I'm going to interchange
03:53
rows 1 and Row 2 maybe because I like to
03:57
have a 1 up in that top place ok and
04:02
then I'm going to use this thing here to
04:04
get rid of the 2 below it so I'm going
04:06
to replace Row 2 with Row 2 minus 2 Row
04:10
1 that will give us 1 3 0 0 4 minus 6 is
04:16
minus 2 1 minus 0 is 1
04:19
great it's now in row echelon form we
04:24
can see that it does have a unique
04:25
solution because the last column is not
04:28
leading and there are no non leading
04:32
columns on the left-hand side so to
04:35
carry on now what we're going to do is
04:37
we're going to replace r2 with minus 1/2
04:42
times Row two those we're going to
04:44
divide by -2 to get 1 3 0 0 1 ok then we
04:51
multiplied by minus 1/2 so they get
04:53
minus 1/2 over here and then we're going
04:56
to sort of go upwards we're gonna take
04:58
this thing and get rid of that 3 so we
05:01
take Row 1 equals row 1 minus 3 times
05:06
Row 2 and that gives us the 1
05:10
I guess this one from stays where it is
05:11
we can write that one first and then 3
05:16
minus 3 is 0 and 0 minus 3 times 3
05:21
halves is
05:22
I guess of 3 halves okay so therefore
05:24
what we see is that the solution is say
05:27
XY equals 3 halves minus 1/2 ok now we
05:37
could do this again in fact we need to
05:39
do it a second time because we need to
05:42
then get the second call this is our
05:43
serve our first column to get the second
05:46
column we need to do the same thing with
05:48
2 4 1 3 0 1 ok let's do that ok so I'm
05:55
not gonna write them all down I'll just
05:56
do them quickly 1/3 what else well swap
05:58
the entries I'm going to take this row 2
06:06
minus 2 times Row 1 so that's 0 minus 2
06:09
0 minus -2 then I'm going to divide that
06:15
second row by minus 2 giving us 1 1 and
06:20
then I'm going to subtract 3 times the
06:25
second row from the first row keep us
06:27
wide and 0 3 minus 3 times 1 minus 3 is
06:32
- - I guess so therefore that gives us X
06:35
y equals -2 1 ok great
06:39
so we have found two columns two column
06:43
vectors that solve these these kind of
06:49
equations so we're finding solutions
06:52
when the right-hand side is one of these
06:54
basis vectors and so now we can put
06:55
those together into a matrix and so we
06:59
can therefore deduce that a inverse
07:01
should be the first one was three halves
07:04
minus 1/2 and the next one was minus 2 1
07:12
all right I have to check it just to
07:14
make sure I've done things right so
07:16
let's check our original matrix a times
07:20
a inverse was what 2 4 1 3 and then 3
07:24
halves minus 1/2 minus 2y is this really
07:28
the inverse 3 1/2 times 2 is 3 minus 2
07:33
is 1 below it 3 halves minus 3 have 0
07:37
over the right - 4 plus 4 is 0 and below
07:41
it - 2 plus 3 is 1 all right great
07:44
that really is the inverse okay so yeah
07:50
that's that's good so that's kind of a
07:52
procedure but now we just want to be a
07:54
little bit more efficient okay we'll
07:55
just notice that in these two procedures
08:00
basically we were performing the same
08:02
operations
08:04
it was repetitive we're basically doing
08:06
the same thing the only thing is
08:08
changing is that the rightmost column in
08:11
the two cases was a little bit different
08:12
but what happens on the left hand side
08:15
is the same throughout that gives us the
08:18
idea that we could do them both at the
08:20
same time ok that's clever little idea
08:25
ok so let's do both columns at the same
08:36
time ok so to illustrate that I'm not
08:40
going to do it again to that one I'm
08:42
gonna do it with a more challenging
08:43
example of a 3x3 maker
08:46
so let's let a be the matrix let's say 2
08:53
0 0 1 2 1 0 1 2 we want to find the
09:00
inverse of this matrix what we're going
09:03
to do is consider a kind of large
09:09
Augmented matrix and Augmented Augmented
09:13
matrix perhaps and we'll write it like
09:19
this
09:20
a on the left and the identity matrix on
09:23
the right okay in other words we're
09:25
going to consider them augmented matrix
09:27
that has a on the left as usual but
09:30
instead of just having one column say 1
09:32
0 0 1 of the basis vectors we're going
09:35
to also add a second column for the
09:37
second basis vector add a third column
09:40
for the third basis vector and we're
09:43
going to perform row reduction on this
09:46
so that the left-hand side ends up in
09:49
reduced row echelon form and then we'll
09:52
have simultaneously solved all three of
09:54
the equations how's that sound
09:57
okay good all right so let's do that let
10:01
us do some row reduction okay but we're
10:04
gonna just still work on the whole level
10:06
of rows so maybe first I'm going to swap
10:08
r1 and r2 just to get a 1 up in that top
10:13
place to 0 0 1 0 0 0 1 2 0 0 1
10:20
great now I'm going to use this thing
10:23
here to get rid of the 2 below it so R
10:28
to the new r2 is the old r2 minus 2 r1
10:32
ok so that's 1 2 1 0 1 0 2 minus 2 is 0
10:38
0 minus 2 times 2 is minus 4 0 minus 2
10:42
times 1 is minus 2 1 minus 0 is 1 0
10:48
minus 2 times 1 is minus 2 and 0 minus 2
10:52
times 0 is 0 the third row in this case
10:55
is staying where it is
11:00
okay good
11:01
now I'm going to move to this lower
11:05
matrix but I don't like the fact that
11:07
there's a minus four there so I'm going
11:10
to swap rows two and three okay so
11:16
that'll be 1 2 1 0 1 0 0 1 2 0 0 1 0
11:23
minus 4 minus 2 1 minus 2 0 now I have a
11:29
1 in that leading place which is good
11:32
that makes it easier to get rid of the
11:34
minus 4 below it so we'll do that by new
11:39
Row 3 equals Row 3 plus 4 Row 2 that
11:48
will give us what first row stays where
11:51
it is second row stays where it is and
11:56
this one becomes 0 there a minus 2 plus
12:02
4 times 2 that's 6 1 plus 4 times 0
12:06
minus 2 plus 4 times 0 and 0 plus 4
12:11
times 1 is 4
12:15
ok good
12:17
all right now I'm in row echelon form I
12:21
can see that this thing is gonna have
12:23
solutions actually it for all three of
12:26
the cases that we're kind of doing
12:28
separately so now we want to move to
12:30
reduced row echelon form because we want
12:32
to keep going until that left hand side
12:34
is the identity matrix it's completely
12:37
reduced row echelon form which will mean
12:39
that it's 3 by 3 identity matrix so
12:43
let's divide the third row by 6 to get a
12:50
1 in that spot 1 2 1 0 1 0 0 1 2 0 0 1 0
12:59
0 1 ok now we have some fractions ok 1/6
13:02
minus 1/3 and 2/3 I guess ok so now I'm
13:09
going to use this one here and
13:12
I'm going to use it to get rid of the
13:14
things above it okay so the new Row 2 is
13:18
going to be the old Row 2 minus 2 times
13:22
Row 3 and the new Row 1 will be the old
13:27
Row 1 minus growth rate okay there's a
13:31
bit of fractions here but hopefully no
13:33
not too bad so the bottom row stays
13:36
where it is 1/6 minus 1/3 2/3 then here
13:42
we get 0 1 0 so we're taking this second
13:45
row and subtracting 2 times Row 3
13:49
subtracting 2 times Row 3 I guess it'll
13:52
be minus 1/3 there minus 2 times Row 3
13:56
so plus 2/3 there and 1 minus 4/3 is
14:01
minus 1/3 and as far as the top row goes
14:06
will there be a 1 to 2 and then a 0 and
14:09
then 0 minus 6 is minus 1/6 and then 1
14:13
minus minus 2/3 looks like 4/3 and 0
14:17
minus 2/3 is minus 2/3 almost there one
14:23
more thing we'll take this element and
14:25
get rid of that - so the new Row 1 is
14:28
the old Row 1 minus 2 times Row 2 to get
14:32
0 0 1 1 6 minus 1/3 2/3 give yourself
14:39
lots of room 0 1 0 minus 1/3 2/3 minus
14:45
1/3 trying to be neat also ok here we go
14:48
this first row of minus 2 times the
14:51
second row 1 0 0 ok row 1 minus 2 times
14:56
Row 2 ok so minus 1/6 that's plus 2/3
15:01
1/6 minus 1/6 plus 2/3 2/3 same as 4 6
15:06
just subtract 1 6 I get 3 6 which is 1/2
15:10
I think ok next
15:13
4/3 minus 2 times 4/3 ok that's 0 and
15:18
then minus 2/3 minus 2 times minus 1/3
15:24
that's also 0
15:26
okay so we are now done the three y
15:33
vectors that we got are just these ones
15:38
here so these are the individual
15:40
solutions to ax equals e I but we've
15:44
done them all at once and the matrix
15:46
that they form is self-evidently sitting
15:49
right there in front of us so this is
15:51
the identity matrix on the left and a
15:54
inverse on the right so we conclude that
15:59
a inverse is the matrix one half 0 0
16:05
minus 1/3 2/3 minus 1/3 1/6 minus 1/3
16:13
2/3 okay and if you're doing this fast
16:18
there's always a pretty good chance that
16:20
you've made a mistake so how do you
16:22
check whether you may have made a
16:24
mistake you would multiply a times a
16:27
inverse and hopefully you will get the
16:30
identity matrix dare we do that okay so
16:34
let's take a universe and multiply it by
16:35
a so 1/2 0 0 minus 1/3 2/3 minus 1/3 1/6
16:42
minus 1/3 2/3 there's a nose and a was
16:46
up at the top 2 0 0 1 2 1 0 1 2 2 0 0 0
16:54
1 2 1 2 1 0 1 2 3 1 2 1 1 2 1 0 1 2 okay
17:07
let's do this multiplication
17:10
ok first column time each of the rows
17:13
what do we get 1/2 times 2 well 0 plus 0
17:16
that's 1 you'll owe it minus 2/3 plus
17:19
2/3 that's 0 1 6 times two is 1/3 minus
17:24
1/3 and that's 0 that's 0 ok next column
17:29
0 2 & 1 0 times 1/2 plus 0 plus 0 is 0 0
17:35
times minus 1/3 plus 4/3
17:39
plus 4/3 minus 1/3 that's three thirds
17:41
or one below that zero minus 2/3 plus
17:45
2/3 that's zero okay things are looking
17:46
good
17:47
and finally this thing here 0 times 1/2
17:53
plus 0 from 0 that's 0 and 0 plus 2/3
17:56
minus 2/3 is 0 and 0 minus 1/3 plus 4/3
18:01
Zazzle 3/3 which is why so we get a
18:06
inverse a equals the identity matrix and
18:09
so we don't have to have to check the
18:13
other one because if we have a right
18:14
inverse we now know we have a left
18:16
inverse too so the thing is invertible
18:18
and our calculation is correct and
18:22
that's it okay so that's a solid a
18:25
little bit computationally intensive but
18:29
it's it's very elegant kind of way of
18:32
computing an inverse of a matrix and
18:35
actually there's not much of a better
18:37
way by hand there's not you know
18:40
formulas which are much better than that
18:43
so this is this is life calculating
18:46
inverses even an ordinary arithmetic is
18:49
complicated in matrix arithmetic it's
18:51
you know cumbersome and it's the size of
18:54
the matrix gets big well then the job
18:56
gets gets more difficult but this at
18:59
least is a surefire technology