Main content

## Transformations and matrix multiplication

# Distributive property of matrix products

## Video transcript

Let's say we have three
matrices, A, B, and C. And let's say that B and C are
both m by n matrices, and that A is a, let's call it
a k by m matrix. And what I want to do is figure
out whether matrix products exhibit the
distributive property. So let's test out A
times B plus C. And of course these
are all matrices. So B, just to make things clear,
the matrix B could be represented as just a bunch of
column vectors, B1, B2, all the way to Bn. And the matrix C can also be
represented as just a bunch of column vectors. So could the matrix A,
but I don't have to draw that just yet. So the matrix C could just be
represented as a bunch of column vectors, C1, C2,
all the way to Cn. Maybe I should've drawn
this taller. These are column vectors, so
they actually have some verticality to them. I think you've seen that
multiple times. So what is A times B plus C? Well, let's figure out
what B plus C is. This is equal to A
times B plus C. When you add B plus C, the
definition of matrix addition is, you just add the
corresponding columns. Which essentially boils
down to adding the corresponding entries. So the first column is going
to be equal to B1 plus C1. The second column is going
to be B2 plus C2. And you're going to go all the
way to the nth column. It's going to be Bn plus Cn. Now by our definition of
matrix-matrix products, this product right here is going to
be equal to the matrix, where we take the matrix A and
multiply it by each of the column vectors of this matrix
here, of B plus C. Which as you can imagine,
these are both m by n. In fact they both have to have
the same dimensions for this addition to be well defined. So this is going to be
an m by n matrix. I already you told you
that A is a k by m. And we know this is well defined
because A has the same number of columns as B
plus C has of rows. So this is well defined. And this is going to be equal
to-- let me switch colors again-- A times the column
vector B1 plus C1. The second column is going to
be A times the column vector B2 plus C2. I'm running out of space. This is going to be all the
way to A times the column vector Bn plus Cn. This is our definition of
matrix-matrix products. You just take the first matrix
and you multiply it times each of the column vectors of
the second matrix. And we can say that because
we've already defined matrix-vector products. So what is this thing on
the right equal to? I'll keep switching colors. We know that matrix-vector
products exhibit the distributive property. I don't even remember when
I did that video. But we've assumed
it for a while. It's a very trivial
thing to prove. So each of these columns is
going to be equal to, let me write this way. This guy right here
can be re-written. The first column is going to be
A times column vector B1, plus A times the column
vector C1. This term right there
is the same thing as that term right there. The next one is going to
be AB2 plus matrix A times the vector C2. And then the nth column is going
to be the matrix-- keep going-- A times the column
vector Bn, plus matrix A times the column vector C. Just like that. Now we can write this
matrix as the sum of two different matrices. So what is this going
to be equal to? This is equal to-- let me see,
I'll just write it right here-- AB1 as the first column,
AB2 as the second column, all the way to ABn
as the third column. So that's these terms
right there. And then if I were to add to
that the matrix A times vector C1, A times the column vector
C2-- these are just the different columns of this
matrix-- and we just then have the matrix A times the
column vector Cn. These represent these terms. So clearly if I add these two
matrices, I just add the corresponding column vectors
and I'll get this matrix up here. But what is this equal to? This right here, by definition,
this is the matrix A times the matrix B. The definition of matrix
products is you take the first matrix and multiply times
the column vectors of the second matrix. And by the same argument, I
guess you could say, this is equivalent to A times C. And all of this-- remember we
just had a bunch of equal signs-- is equal to
A times B plus C. So now we can say definitively
that as long as the products are well defined and the sums
are well difined, so they all have to have the correct
dimensions, that A times B plus C is equal to AB plus AC. So matrix products do exhibit
the distributive property, at least in this direction. And I say that because remember
matrix products are not commutative. So we don't know necessarily
that B plus C times A is equivalent to that. In fact, most of the time
these two things are not equivalent. So we don't know quite yet
that if we reversed this, whether it's still going
to exhibit the distributive property. So let's try to do that. And I'll do it a little bit
quicker, because I think you know the general
argument here. So let's take B plus
C times A. And I'll just write A as
its column vectors. A1, A2, all the way to-- A has
m columns if I remember correctly, right A has
m columns-- so all the way to Am. And by the definition of matrix
products, this is going to be equal to the matrix--
B plus C is just a matrix, right? We can represent it as the
sum of two matrix, but it is just a matrix. So it's B plus C times each of
the column vectors of A. So it's going to be equal to
B plus C times A1, B plus C times A2, all the way to
B plus C times An. And, once again, it was many
videos ago that I think we showed that matrix-vector
products are distributive, so we can just distribute
this vector along these two matrices. And if I haven't proven it
yet, it's actually a very straightforward prove to do. So we could say that this is
equal to BA1 plus CA2. That's the first column. The second column is B times A2,
plus C times A2, all the way to B times An,
plus C times An. And then what is
this equal to? I'll write it out. This is equivalent to B times--
this is A1, no this is an A1 right here-- A1, and then
B times A2, all the way to BAn plus the vector C times
A1, C times A2, all the way to C times An, right? This guy represents these terms
right there, and this guy represents the first
terms in each of these column vectors. And this, by the definition of
matrix products, is just equivalent to BA, and then this
is just equivalent to CA. So now we've seen that the
distributive property works both ways with matrix-vector
products. That B plus C times A is equal
to BA CA, and that A times B plus C is equal to AB plus AC. Now the one thing that you have
to be careful of is that these two things are not
equivalent [UNINTELLIGIBLE]. We just figured out that this
guy is equal to BA plus CA. So the distribution works
in both ways. But when you're dealing with
matrices, it's very important to keep your order. So this is going to be you
have the A second here. So it is BA plus CA. You can't say that this is
equal to AB plus AC. You can't just switch
these up. Because we've shown multiple
times, or we've talked about it multiple times, that matrix
products are not commutative. You can't just switch the
order of the products. But we've at least shown
in this video that the distributive property
works both ways.