# Multiplying matrices, need some clarification simple dot product

I understand that when you want to multiply two matrices that the number of rows in the left matrix have to be equal to the number of columns in the right, otherwise the result of the multiplication is undefined.

So this is okay:

$\begin{bmatrix}1&2&3\\4&5&6\end{bmatrix}*\begin{bmatrix}7&8\\9&10\\11&12\end{bmatrix}=\begin{bmatrix}58&64\\139&154\end{bmatrix}$

This is undefined:

$\begin{bmatrix}1&2&3\\4&5&6\end{bmatrix}*\begin{bmatrix}7&8&9\\10&11&12\end{bmatrix}=undefined$

But what exactly happens here?

$\begin{bmatrix}1&2&3\\4&5&6\end{bmatrix}*\begin{bmatrix}7&8\\9&10\\11&12\\13&14\\15&16\end{bmatrix}=\begin{bmatrix}?\end{bmatrix}$

The number of rows in the first matrix is equal to the number of columns in the second matrix, so by what I've been reading online this is doable. I'm just not sure how to accomplish this because all the examples I've seen only have shown the first example where there multiplication of elements is 1:1, I haven't seen any examples explaining what to do in the third case.

If I was to guess, I would say that we're supposed to multiply all the elements through but I want to know what the actual rule and process for this is before I commit something incorrect to memory by guessing.

Thanks to all in advance, I know this question is a bit simplistic.

-
It's the number of columns in the first matrix that has to be equal to the number of rows in the second matrix. – Qiaochu Yuan May 20 '14 at 17:13

The inner dimensions need to match (# of columns in first matrix = # of rows in second matrix). If $A$ is m by n (m rows, n columns), and $B$ is n by p, then $AB$ is m by p (and is undefined otherwise). The i-j'th component (ith row, jth column) of $AB$ is the $i$-th row of $A$ dotted with the $j$-th column of $B$.