How To Multiply Matrices With Different Dimensions

6 min read

Matrix multiplication is a cornerstone operation in linear algebra, powering everything from computer graphics and machine learning algorithms to economic modeling and quantum mechanics. Which means unlike scalar multiplication or matrix addition, the rules governing the product of two matrices are strict regarding their dimensions. Understanding how to multiply matrices with different dimensions requires mastering the compatibility condition and the systematic dot-product process. This guide breaks down the requirements, the step-by-step mechanics, the mathematical intuition, and common pitfalls to ensure you can perform this operation confidently.

The Fundamental Rule: Dimension Compatibility

Before attempting any calculation, you must verify that the operation is mathematically defined. The golden rule for matrix multiplication is simple but unforgiving: the number of columns in the first matrix must equal the number of rows in the second matrix.

If Matrix $A$ has dimensions $m \times n$ ($m$ rows, $n$ columns) and Matrix $B$ has dimensions $p \times q$ ($p$ rows, $q$ columns), the product $AB$ is only possible if $n = p$. The inner dimensions must match.

When the multiplication is valid, the resulting matrix $C = AB$ will adopt the outer dimensions. Which means, the product of an $m \times n$ matrix and an $n \times q$ matrix yields a new matrix of dimensions $m \times q$.

Visualizing the Rule:

  • Valid: $(2 \times 3) \times (3 \times 4) \rightarrow$ Result is $2 \times 4$.
  • Valid: $(1 \times 5) \times (5 \times 1) \rightarrow$ Result is $1 \times 1$ (a scalar).
  • Invalid: $(3 \times 2) \times (3 \times 4) \rightarrow$ Inner dimensions $2 \neq 3$. Operation undefined.
  • Invalid: $(2 \times 2) \times (3 \times 3) \rightarrow$ Inner dimensions $2 \neq 3$. Operation undefined.

It is crucial to remember that matrix multiplication is not commutative. Think about it: even if both $AB$ and $BA$ are defined (which happens only when both are square matrices of the same size, or specific rectangular combinations), $AB \neq BA$ in the general case. The order of multiplication fundamentally changes the result—or determines if a result exists at all.

Step-by-Step Calculation: The Dot Product Method

Once compatibility is confirmed, the calculation proceeds by computing the dot product (also known as the inner product) of rows from the first matrix with columns from the second matrix Took long enough..

The Algorithm

To find the element $c_{ij}$ located at row $i$, column $j$ of the result matrix $C$:

  1. Select Row $i$ from Matrix $A$.
  2. Select Column $j$ from Matrix $B$.
  3. Multiply corresponding entries pairwise.
  4. Sum those products.

$c_{ij} = \sum_{k=1}^{n} a_{ik} b_{kj}$

Worked Example: $2 \times 3$ multiplied by $3 \times 2$

Let Matrix $A$ be $2 \times 3$ and Matrix $B$ be $3 \times 2$. $A = \begin{bmatrix} 1 & 2 & 3 \ 4 & 5 & 6 \end{bmatrix}, \quad B = \begin{bmatrix} 7 & 8 \ 9 & 1 \ 2 & 3 \end{bmatrix}$

Check: Inner dimensions are $3$ and $3$. Match. Result will be $2 \times 2$ Nothing fancy..

Calculate $c_{11}$ (Row 1 of A $\cdot$ Column 1 of B): $(1 \times 7) + (2 \times 9) + (3 \times 2) = 7 + 18 + 6 = 31$

Calculate $c_{12}$ (Row 1 of A $\cdot$ Column 2 of B): $(1 \times 8) + (2 \times 1) + (3 \times 3) = 8 + 2 + 9 = 19$

Calculate $c_{21}$ (Row 2 of A $\cdot$ Column 1 of B): $(4 \times 7) + (5 \times 9) + (6 \times 2) = 28 + 45 + 12 = 85$

Calculate $c_{22}$ (Row 2 of A $\cdot$ Column 2 of B): $(4 \times 8) + (5 \times 1) + (6 \times 3) = 32 + 5 + 18 = 55$

Result Matrix $C$ ($2 \times 2$): $C = \begin{bmatrix} 31 & 19 \ 85 & 55 \end{bmatrix}$

Worked Example: $3 \times 2$ multiplied by $2 \times 3$ (Reverse Order)

Using the same matrices but swapping order ($B \times A$). $B$ is $3 \times 2$, $A$ is $2 \times 3$. Consider this: Check: Inner dimensions $2$ and $2$. But **Match. ** Result will be $3 \times 3$.

Notice immediately that the output shape ($3 \times 3$) differs from the previous result ($2 \times 2$). This highlights the non-commutative nature.

$B \times A = \begin{bmatrix} 7 & 8 \ 9 & 1 \ 2 & 3 \end{bmatrix} \begin{bmatrix} 1 & 2 & 3 \ 4 & 5 & 6 \end{bmatrix}$

Calculating just the first row of the result:

  • $c_{11} = (7 \times 1) + (8 \times 4) = 7 + 32 = 39$
  • $c_{12} = (7 \times 2) + (8 \times 5) = 14 + 40 = 54$
  • $c_{13} = (7 \times 3) + (8 \times 6) = 21 + 48 = 69$

The resulting $3 \times 3$ matrix is entirely different from the $2 \times 2$ matrix produced by $A \times B$.

Alternative Perspectives: Columns and Rows

While the row-by-column dot product is the standard computational method, viewing multiplication through different lenses deepens understanding and aids in debugging code or deriving proofs Simple, but easy to overlook..

1. Linear Combination of Columns (Column View)

The product $AB$ can be viewed as Matrix $A$ multiplying each column of $B$ independently. The $j$-th column of the result $C$ is simply the matrix-vector product of $A$ and the $j$-th column of $B$. $C_{:,j} = A \times B_{:,j}$ This perspective is extremely useful in linear transformations. It shows that the columns of the result are linear combinations of the columns of $A$, weighted by the entries in the corresponding column of $B$ Still holds up..

2. Linear Combination of Rows (Row View)

Symmetrically, the $i$-th row of the result $C$ is the vector-matrix product of the $i$-th row of $A$ with the entire Matrix $B$. $C_{i,:} = A_{i,:} \times B$ Here, the rows of the result are linear combinations of the rows of $B$, weighted by the entries in the corresponding row of $A$.

3. Sum of Outer Products

For advanced applications (like Singular Value Decomposition or low-rank approximations), the matrix product can

be expressed as a sum of rank-1 matrices (outer products). Each term in the sum is formed by multiplying a column of $A$ with the corresponding row of $B$ That's the part that actually makes a difference..

$AB = \sum_{k=1}^{n} \text{(Column } k \text{ of } A) \times \text{(Row } k \text{ of } B)$

For our example, this would be: $(\text{Col}_1 \text{ of } A)(\text{Row}_1 \text{ of } B) + (\text{Col}_2 \text{ of } A)(\text{Row}_2 \text{ of } B) + (\text{Col}_3 \text{ of } A)(\text{Row}_3 \text{ of } B)$

This view is powerful for understanding the structure of the resulting matrix and is foundational in many numerical algorithms Not complicated — just consistent. And it works..

Conclusion

Mastering matrix multiplication is more than memorizing a formula; it's about developing an intuitive grasp of its multiple interpretations. Whether you're calculating a single entry, building the result column-by-column, row-by-row, or as a sum of outer products, each perspective offers a unique insight. On the flip side, this flexibility is not just academic—it is the key to efficiently implementing and debugging matrix operations in fields ranging from computer graphics and machine learning to physics and economics. By understanding these interconnected views, you transform a simple arithmetic procedure into a versatile and powerful tool for modeling relationships between data Still holds up..

More to Read

New Writing

Same World Different Angle

Before You Head Out

Thank you for reading about How To Multiply Matrices With Different Dimensions. We hope the information has been useful. Feel free to contact us if you have any questions. See you next time — don't forget to bookmark!
⌂ Back to Home