Skip to main content
Home / Matrices / Matrix Multiplication
Calculating...
Matrix Operation

Matrix Multiplication Calculator

Multiply two matrices A (m×k) and B (k×n) using the row-column rule. The result C = A×B has dimensions m×n, where each entry Cᵢⱼ is the dot product of row i of A and column j of B. Matrix multiplication is not commutative (AB ≠ BA generally), but it is associative and distributive

Home Matrix Operations Matrix Multiplication
Two matrices

Matrix A

Rows (m):
×
Cols (k):
r1
r2
r3
r4
r5
r6
r7
r8
r9
r10
c1
c2
c3
c4
c5
c6
c7
c8
c9
c10

Matrix B

Rows (k):
×
Cols (n):
r1
r2
r3
r4
r5
r6
r7
r8
r9
r10
c1
c2
c3
c4
c5
c6
c7
c8
c9
c10

Learn About Matrix Multiplication

Understanding the concepts behind the calculations.


What is Matrix Multiplication?

Matrix multiplication is NOT element-wise multiplication. It is a row-column operation where each entry in the product is the dot product of a row from the first matrix and a column from the second matrix.

Definition: If A is an m×n matrix and B is an n×p matrix, then C = A·B is an m×p matrix where:

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

Each entry cᵢⱼ = (row i of A) · (column j of B)

⚠️ IMPORTANT: Matrix multiplication is NOT commutative! A·B ≠ B·A in general.

Visual Representation

$$ \begin{bmatrix} \color{blue}{a_{11}} & \color{blue}{a_{12}} \\\\ a_{21} & a_{22} \end{bmatrix} \cdot \begin{bmatrix} \color{blue}{b_{11}} & b_{12} \\\\ \color{blue}{b_{21}} & b_{22} \end{bmatrix} = \begin{bmatrix} \color{blue}{a_{11}b_{11} + a_{12}b_{21}} & * \\\\ * & * \end{bmatrix} $$

The entry at (1,1) comes from row 1 of A and column 1 of B.


The Dimension Rule: Inner Dimensions Must Match

Dimension Compatibility: For A·B to be defined:

$$ A_{m \times \color{red}{n}} \cdot B_{\color{red}{n} \times p} = C_{m \times p} $$

The number of columns of A must equal the number of rows of B.

✅ Valid Multiplications:

  • 2×3 · 3×4 = 2×4 ✓
  • 3×3 · 3×3 = 3×3 ✓
  • 1×5 · 5×1 = 1×1 ✓ (dot product)
  • 4×2 · 2×3 = 4×3 ✓

❌ Invalid Multiplications:

  • 2×3 · 2×3 ✗ (inner: 3 ≠ 2)
  • 3×2 · 3×3 ✗ (inner: 2 ≠ 3)
  • 4×1 · 4×1 ✗ (inner: 1 ≠ 4)

💡 Memory Trick: Write dimensions side by side: (m × n)(n × p) → (m × p). The inner numbers (n) must match, and they "cancel" to give outer dimensions.


How to Multiply: Row × Column

The Process

  1. Take row i from the first matrix A
  2. Take column j from the second matrix B
  3. Multiply corresponding elements and sum them up (dot product)
  4. Place result in position (i, j) of the product matrix C
  5. Repeat for all i and j

Example: 2×2 Multiplication

$$ \begin{bmatrix} a & b \\\\ c & d \end{bmatrix} \cdot \begin{bmatrix} e & f \\\\ g & h \end{bmatrix} = \begin{bmatrix} ae + bg & af + bh \\\\ ce + dg & cf + dh \end{bmatrix} $$
  • Entry (1,1): (row1 of A) · (col1 of B) = a·e + b·g
  • Entry (1,2): (row1 of A) · (col2 of B) = a·f + b·h
  • Entry (2,1): (row2 of A) · (col1 of B) = c·e + d·g
  • Entry (2,2): (row2 of A) · (col2 of B) = c·f + d·h

Properties of Matrix Multiplication

✓ Associative

$$ (AB)C = A(BC) $$

Order of multiplication doesn't matter for grouping.

✓ Distributive

$$ A(B + C) = AB + AC $$

Multiplication distributes over addition.

✗ NOT Commutative

$$ AB \neq BA \quad \text{(in general)} $$

Order MATTERS! Always specify which is first.

✓ Identity Matrix

$$ AI = IA = A $$

The identity matrix I acts like 1 for multiplication.

Additional Properties

  • Transpose: (AB)ᵀ = BᵀAᵀ (notice order reversal!)
  • Scalar multiplication: c(AB) = (cA)B = A(cB)
  • Zero matrix: A·0 = 0 and 0·A = 0

📌 Important: Unlike regular numbers, matrix multiplication is not commutative. AB and BA may not even have the same dimensions!


Step-by-Step Examples

Example 1: 2×2 × 2×2

Problem: Multiply A·B

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

Step 1: Check dimensions → 2×2 · 2×2 = 2×2 ✓

Step 2: Compute entry C₁₁ (row1·col1):

$$ (1)(5) + (2)(7) = 5 + 14 = 19 $$

Step 3: Compute entry C₁₂ (row1·col2):

$$ (1)(6) + (2)(8) = 6 + 16 = 22 $$

Step 4: Compute entry C₂₁ (row2·col1):

$$ (3)(5) + (4)(7) = 15 + 28 = 43 $$

Step 5: Compute entry C₂₂ (row2·col2):

$$ (3)(6) + (4)(8) = 18 + 32 = 50 $$

Result:

$$ C = \begin{bmatrix} 19 & 22 \\\\ 43 & 50 \end{bmatrix} $$

Example 2: 2×3 × 3×2

Problem: Multiply A·B (notice inner dimension 3 matches!)

$$ A = \begin{bmatrix} 1 & 2 & 3 \\\\ 4 & 5 & 6 \end{bmatrix}, \quad B = \begin{bmatrix} 7 & 8 \\\\ 9 & 10 \\\\ 11 & 12 \end{bmatrix} $$

Result will be 2×2

C₁₁: Row1·Col1 = 1·7 + 2·9 + 3·11 = 7 + 18 + 33 = 58

C₁₂: Row1·Col2 = 1·8 + 2·10 + 3·12 = 8 + 20 + 36 = 64

C₂₁: Row2·Col1 = 4·7 + 5·9 + 6·11 = 28 + 45 + 66 = 139

C₂₂: Row2·Col2 = 4·8 + 5·10 + 6·12 = 32 + 50 + 72 = 154

$$ C = \begin{bmatrix} 58 & 64 \\\\ 139 & 154 \end{bmatrix} $$

Example 3: Demonstrating Non-Commutativity

Show that AB ≠ BA

$$ A = \begin{bmatrix} 1 & 2 \\\\ 0 & 1 \end{bmatrix}, \quad B = \begin{bmatrix} 1 & 0 \\\\ 1 & 1 \end{bmatrix} $$

AB:

$$ AB = \begin{bmatrix} 1+2 & 0+2 \\\\ 0+1 & 0+1 \end{bmatrix} = \begin{bmatrix} 3 & 2 \\\\ 1 & 1 \end{bmatrix} $$

BA:

$$ BA = \begin{bmatrix} 1+0 & 2+0 \\\\ 1+0 & 2+1 \end{bmatrix} = \begin{bmatrix} 1 & 2 \\\\ 1 & 3 \end{bmatrix} $$

Conclusion: AB ≠ BA, proving matrix multiplication is not commutative!


Special Cases

CaseDescriptionExample
Square × SquareMost common case3×3 · 3×3 = 3×3
Row Vector × Column VectorDot product (scalar result)1×n · n×1 = 1×1
Column Vector × Row VectorOuter product (matrix result)n×1 · 1×m = n×m
Identity Matrix IAI = A and IA = AI acts like 1
Zero Matrix 0A·0 = 0 and 0·A = 0Zero matrix times anything = zero
Symmetric × SymmetricProduct may not be symmetric!AB not necessarily symmetric

Real-World Applications

🤖 Machine Learning

  • Neural Networks: Layer transformations = weight matrix × input vector
  • Linear Regression: Predictions = X·β
  • Principal Component Analysis (PCA): Projections = X·V
  • Word Embeddings: Word2Vec, GloVe use matrix multiplications

🎮 Computer Graphics

  • 3D Transformations: Rotation, scaling, translation matrices
  • Camera Projections: 3D → 2D via matrix multiplication
  • Animation: Skeletal transformations

🔬 Engineering

  • Control Systems: State-space models (x' = Ax + Bu)
  • Structural Analysis: Stiffness matrices
  • Signal Processing: Filtering and convolution

📊 Economics

  • Input-Output Models: x = Ax + d → (I-A)x = d
  • Portfolio Optimization: Risk calculations
  • Markov Chains: πₙ = π₀·Pⁿ

Common Mistakes to Avoid

  1. Multiplying incompatible dimensions → Always check that columns of A = rows of B
  2. Assuming commutativity → AB ≠ BA in most cases! Always respect order
  3. Element-wise multiplication confusion → Matrix multiplication uses dot products, not multiplying corresponding entries
  4. Forgetting that (AB)ᵀ = BᵀAᵀ → Notice the order reversal!
  5. Misplacing the summation → Make sure you sum ALL products from k=1 to n
  6. Incorrect dimension of result → Result dimensions are (rows of A) × (columns of B)

Frequently Asked Questions

Q: Why isn't matrix multiplication commutative?

A: Because the row-column operation is directional. Row i of A pairs with column j of B. Swapping changes which rows pair with which columns, usually giving different results.

Q: Can I multiply a 3×2 matrix by a 3×2 matrix?

A: No. For 3×2 · 3×2, inner dimensions are 2 (from first) and 3 (from second). 2 ≠ 3, so undefined.

Q: Is matrix multiplication associative?

A: Yes! (AB)C = A(BC) whenever the dimensions allow the products. This is very useful for computing efficiency.

Q: What is the identity matrix and why is it special?

A: Identity I has 1s on diagonal, 0s elsewhere. For any compatible A: A·I = A and I·A = A. It's the multiplicative identity element.

Q: How does matrix multiplication relate to linear transformations?

A: Each matrix represents a linear transformation. Matrix multiplication corresponds to composition of transformations (apply one, then the other).

Q: What's the cost of multiplying matrices?

A: For m×n and n×p matrices, naive multiplication requires m·n·p multiplications. For 2×2: 8 multiplications. For 100×100: 1 million!


Practice Problems

Beginner

  1. Multiply:

    $$ \begin{bmatrix} 1 & 0 \\\\ 0 & 1 \end{bmatrix} \cdot \begin{bmatrix} 4 & 5 \\\\ 6 & 7 \end{bmatrix} $$
  2. Compute the dot product (1×2 · 2×1):

    $$ \begin{bmatrix} 2 & 3 \end{bmatrix} \cdot \begin{bmatrix} 4 \\\\ 5 \end{bmatrix} $$

Intermediate

  1. Multiply:

    $$ \begin{bmatrix} 2 & -1 \\\\ 0 & 3 \end{bmatrix} \cdot \begin{bmatrix} 1 & 4 \\\\ -2 & 1 \end{bmatrix} $$
  2. If A is 3×4 and B is 4×2, what are the dimensions of AB?

Advanced

  1. Find two 2×2 matrices where AB = 0 but neither A nor B is zero.

  2. Show that (AB)ᵀ = BᵀAᵀ using A = [[1,2],[3,4]] and B = [[5,6],[7,8]]

Click to reveal solutions

1. Same as B: [[4, 5], [6, 7]] (identity matrix)

2. 2·4 + 3·5 = 8 + 15 = 23 (scalar, not matrix)

3. [[4, 7], [-6, 3]]

4. 3×2

5. Example: A = [[1,0],[0,0]], B = [[0,0],[0,1]]

6. Compute both sides to verify equality



Summary

🎯 Key Takeaways

  • Matrix multiplication is NOT element-wise — it's row × column dot products
  • Dimension rule: (m×n)(n×p) = (m×p) — inner dimensions must match
  • NOT commutative: AB ≠ BA in general — order matters!
  • IS associative: (AB)C = A(BC) — grouping doesn't matter
  • Identity I: AI = IA = A — acts like 1 for multiplication
  • Applications: Neural networks, graphics, control systems, economics

💡 Quick Memory Aid: "Rows of A, columns of B, dot product in the middle!"

Try It Yourself!

Use the calculator above to multiply matrices:

  1. Enter Matrix A (first matrix)
  2. Enter Matrix B (second matrix — must have compatible dimensions)
  3. Click "Calculate" to see:
    • The dimension check (inner dimensions must match)
    • Each entry's dot product calculation
    • The resulting product matrix C = A·B
    • Step-by-step verification

📐 Test these examples:

  • 2×2 multiplication: [[1,2],[3,4]] × [[5,6],[7,8]]
  • Rectangular matrices: [[1,2,3],[4,5,6]] × [[7,8],[9,10],[11,12]]
  • Identity test: Any matrix × Identity = Same matrix
  • Non-commutativity: Try switching the order to see different results!

📐 Pro Tip: Always check dimensions first — our calculator will warn you if they're incompatible!

Press / to search operations