11.2: Matrix Multiply
( \newcommand{\kernel}{\mathrm{null}\,}\)
Read Section 10.1 of the Stephen Boyd and Lieven Vandenberghe Applied Linear algebra book which covers Matrix Multiplication. Here is a quick review:
Two matrices A and B can be multiplied together if and only if their “inner dimensions” are the same, i.e. A is n×d and B is d×m (note that the columns of A and the rows of B are both d). Multiplication of these two matrices results in a third matrix C with the dimension of n×m. Note that C has the same first dimension as A and the same second dimension as B. i.e n×m.
The (i,j) element in C is the dot product of the ith row of A and the jth column of B.
The ith row of A is:
[ai1,ai2,…,aid],
and the jth column of B is:
[b1jb2j⋮bdj]
So, the dot product of these two vectors is:
cij=ai1b1j+ai2b2j+⋯+aidbdj
Consider the simple 2×2 example below:
[abcd][wxyz]=[aw+byax+bzcw+dycx+dz]
Let’s do an example using numpy
and show the results using sympy
:
Given two matrices; A and B, show that order matters when doing a matrix multiply. That is, in general, AB≠BA. Show this with an example using two 3×3 matrices and numpy
.
Now consider the following set of linear equations:
3x1−3x2+9x3= 24
2x1−2x2+7x3= 17
−x1+2x2−4x3=−11
We typically write this in the following form:
[3−392−27−12−4][x1x2x3]=[2417−11]
Notice how doing the matrix multiplication results back into the original system of equations. If we rename the three matrices from above to A, x, and b (note x and b are lowercase because they are column vectors) then we get the main equation for this class, which is:
Ax=b
Note the information about the equation doesn’t change when you change formats. For example, the equation format, the augmented format and the Ax=b format contain the same information. However, we use the different formats for different applications. Consider the numpy.linalg.solve
function which assumes the format Ax=b
What is the size of the matrix resulting from multiplying a 10×40 matrix with a 40×3 matrix?