Game Development Reference
In-Depth Information
4.1.6
Multiplying Two Matrices
In certain situations, we can take the product of two matrices. The rules
that govern when matrix multiplication is allowed and how the result is
computed may at first seem bizarre.
An r×n matrix A may be multiplied by an n×c matrix B . The result,
denoted AB , is an r × c matrix. For example, assume that A is a 4 × 2
matrix, and B is a 2 × 5 matrix. Then AB is a 4 × 5 matrix:
If the number of columns in A does not match the number of rows in B ,
then the multiplication AB is not defined (although BA may be possible).
Matrix multiplication is computed as follows: let the matrix C be the
r×c product AB of the r×n matrix A with the n×c matrix B . Then each
element c ij is equal to the vector dot product of row i of A with column j
of B :
n
c ij =
a ik b kj .
k=1
This looks complicated, but there is a simple pattern. For each element
c ij in the result, locate row i in A and column j in B . Multiply the
corresponding elements of the row and column, and sum the products. c ij
is equal to this sum, which is equivalent to the dot product of row i in A
with column j in B .
Let's look at an example of how to compute c 24 . The element in row 2
and column 4 of C is equal to the dot product of row 2 of A with the
column 4 of B :
 
Search WWH ::




Custom Search