January 22, 2013 Matrix Multiplication a Bartender’s Guide James Baugh
1 Matrices, Row Vectors, and Column Vectors
A matrix is an array of values (or possibly more abstract mathematical objects) with a specific number of rows and columns. We use the ”RC cola” mnemonic to remember the convention of stating number of rows first and number of columns second. We refer to the number of rows and columns as the dimensions of the matrix. Thus below is an example of a 2 × 3 matrix:
1 2 3
0 − π 7
We typically identify a 1 × 1 matrix with the single value it contains. [5] ≡ 5. Note also that we may interchangeably use either parenthesis or square brackets to indicate a matrix. In more specific applications parentheses and brackets may be used to make some important distinction.
Here we make none but may use one of the two to make a particular case stand out.
We treat matrices with the same dimension as vectors in the sense of addition and scalar multiplication with the understanding that we add matrices by adding corresponding components and multiply by a scalar by multiplying each entry by that value. This allows us to expand a matrix in a basis such as: a b c d
= a
1 0
0 0
+ b
0 1
0 0
+ c
0 0
1 0
+ d
0 0
0 1
In the special case where we have only one row or one column we refer to the matrix as, respectively, a row vector or column vector : row vector a b c
column vector
x y z
2 Matrix Multiplication in Stages, a Bartender’s Guide
It is helpful to view a general matrix as equivalent to a row vector of column vectors or to a column vector of row vectors .
1
For example:
1 2 3
0 − π 7
=
[1 2 3]
[0 − π 7]
=
1
0
2
− π
√
7
When viewed this way, once we know how to multiply rows and columns we can recursively multiply arbitrary matrices (or know that the particular case is invalid.)
2.1
Soft Drinks
Remember our ”RC cola” mnemonic? Well it also helps us with multiplying matrices. We can multiply a row vector times a column vector (with matching dimensions) to yield a number. Think of this as a “soft” version of matrix multiplication (“RC” or “Royal Crown” cola being a softdrink ).
This form of multiplication is the essence of the general notion of taking linear combinations.
1
This is a case where we allow a matrix to hold more abstract objects, e.g. other matrices.
Sec. 2 Matrix Multiplication a Bartender’s Guide Page 1
January 22, 2013 Matrix Multiplication a Bartender’s Guide James Baugh
The product of a row vector and column vector each with the same number of entries is the sum of the products of corresponding entries.
The rule is easily understood by an example or two: a b c
x y z
= a · x + b · y + c · z
Note that as matrices we are multiplying here a 1 × 3 times a 3 × 1 to yield a single number (a
1 × 1 matrix). If the number of columns in the row vector does not match the number of rows in the column vector then the product is not valid .
Here is a more concrete example:
5 2
3
4
= 5 · 3 + 2 · 4 = 15 + 8 = 23
Some points to note: The dot product of two vectors can be written out this way provided we use row and column vectors of their components in an ortho-normal basis . We can also use matrix format for dot products in other bases but that gets more involved.
Another point is that the act of expanding a vector in a basis can be written in matrix product format. First we define an ordered basis (put them in a certain order) as the row vector of basis vectors.
2
For example:
B = ˆ
We can then define a component vector as the column vector of components and then a given vector is expressed as the product of the basis with its components thusly: r = h x, y, z i = ˆ
x y z
This is the main way we transition from some system of vectors to the use of matrices. We treat the ordered basis as a linear mapping from column (component) vectors to the actual vectors in the space of interest such as geometric vectors, or functions or some other application. This is where we would start when considering changes of basis.
3 Hard Liquor
When we reverse the mnemonic ”RC cola” or ”Royal Crown cola” we get instead ”Crown Royal” which is a whiskey. This means we’re in the big league! And indeed we can multiply a column vector times a row vector and the result is something bigger and more involved than simply a value.
Here is the rule:
The product of an n dimensional column vector ( n × 1 matrix) and an m dimensional row vector ( 1 × m matrix) is an n × m matrix of products of the corresponding entries
Example:
a ax ay az
b c
x y z =
bx cx by cy bz cz
d dx dy dz
2
Here is another case where we allow more complex entries in the matrix.
Sec. 3 Matrix Multiplication a Bartender’s Guide Page 2
January 22, 2013 Matrix Multiplication a Bartender’s Guide James Baugh
Notice that in this case the dimensions of the column and row vectors do not need to be equal.
Actually treating them as matrices they actually do but it is a different dimension. Earlier for a row (1 × n ) times a column ( n × 1) it is the number of columns on the left which match up with the number of rows on the right ( n = n ).
Here with a column ( n × 1) times a row (1 × m ) again the number of columns on the left must match the number of rows on the right but now we have only one of each. (1 = 1). We can multiply in general an j × k matrix times a n × m matrix provide the ”touching” dimensions are equal ( k = m ).
4 Mixed Drinks
Now we put the two together and define general matrix multiplication. The product of a k × n matrix and an n × m matrix is a k × m matrix obtained by:
• treating the left matrix as a column vector of row vectors ,
• treating the right matrix as a row vector of column vectors , and
• applying the earlier defined rules recursively.
Example: 2 × 3 times a 3 × 4 yields a 2 × 4 a b c x y z
1 2 3 4
5 − 2 − 1 3
0 1 0 − 1
=
[ a b c ]
[ x y z ]
1
5
0
2
− 2
1
3
− 1
0
4
3
− 1
= now multiply Row times column:
=
a b c x y z
1
5
0
1
5
0
a x b y c z
2
− 2
1
2
− 2
1
a x b y c z
3
− 1
0
3
− 1
0
a x b y c z
4
3
− 1
4
3
− 1
=
=
( a + 5 b + 0 c ) (2 a − 2 b + c ) (3 a − b + 0 c ) (4 a + 3 b − c )
( x + 5 y + 0 z ) (2 x − 2 y + z ) (3 x − y + 0 z ) (4 x + 3 y − z )
=
( a + 5 b ) (2 a − 2 b + c ) (3 a − b ) (4 a + 3 b − c )
( x + 5 y ) (2 x − 2 y + z ) (3 x − y ) (4 x + 3 y − z )
Now, you can also reverse the ”column vector of row vector” and ”row vector of column vector” convention and you still get the same product. Working it in reversed will give you a sum (RC) of matrices (CR) rather than this matrix (CR) of sums (RC). But the result is the same. With practice you can work out the whole iteratively in a single step.
Sec. 4 Matrix Multiplication a Bartender’s Guide Page 3