How to Multiply Matrix Variables and Matrices- Linear Algebra Tutorial
What Matrix Multiplication Actually Is
Matrix multiplication isn't like regular multiplication. You can't just multiply numbers in the same positions and call it done. The process involves dot products between rows of the first matrix and columns of the second matrix.
If you've been treating matrix multiplication like regular number multiplication, stop. That's your first mistake.
The Dimension Rule You Must Know
Before you multiply anything, check your dimensions. This is where most people fail.
A matrix is written as rows × columns. If matrix A is (m × n) and matrix B is (p × q), you can only multiply them if n equals p. The result will be an (m × q) matrix.
Example: A (2 × 3) matrix times B (3 × 4) matrix gives you a (2 × 4) result. The inner dimensions must match.
Why This Matters
You can't multiply a 2×3 matrix by a 2×3 matrix. The dimensions don't work. This isn't a suggestion—it's mathematics. The operation is undefined otherwise.
How to Multiply Two Matrices Step by Step
Let's say you have two 2×2 matrices:
A = [ [1, 2], [3, 4] ]
B = [ [5, 6], [7, 8] ]
Here's the process:
- Take the first row of A: [1, 2]
- Take the first column of B: [5, 7]
- Multiply corresponding elements and add them: (1×5) + (2×7) = 5 + 14 = 19
- That's element C[1,1] in your result matrix
Repeat this for every position. The result matrix C:
C[1,1] = 1×5 + 2×7 = 19
C[1,2] = 1×6 + 2×8 = 22
C[2,1] = 3×5 + 4×7 = 43
C[2,2] = 3×6 + 4×8 = 50
Result: C = [ [19, 22], [43, 50] ]
Multiplying a Matrix by a Variable
When you multiply a matrix by a variable (scalar), you multiply every element by that variable. This is simpler than matrix-matrix multiplication.
For 3A where A = [ [2, 4], [6, 8] ]:
Result = [ [3×2, 3×4], [3×6, 3×8] ] = [ [6, 12], [18, 24] ]
This works with any scalar. No dimension checking needed—just distribute the multiplication.
Multiplying Matrix Variables in Equations
In linear algebra, you often see expressions like AX = B, where A and B are known matrices and X is unknown.
To solve for X, you multiply both sides by A⁻¹ (the inverse of A):
A⁻¹A X = A⁻¹B
This simplifies to:
X = A⁻¹B
The key point: you must multiply on the left. You can't write X = B A⁻¹. Matrix multiplication isn't commutative. AB ≠ BA in most cases.
Common Mistakes That Ruin Your Answers
- Multiplying corresponding positions instead of using dot products—wrong method
- Ignoring dimension requirements—undefined result
- Assuming AB = BA—false for most matrices
- Forgetting to multiply every element by a scalar—partial credit at best
- Writing the wrong inverse when solving AX = B—check your work
Matrix Multiplication vs Element-wise Multiplication
These are different operations. Many students confuse them.
| Operation | Method | Dimensions |
|---|---|---|
| Matrix Multiplication | Dot products of rows × columns | Inner dimensions must match |
| Element-wise (Hadamard) | Multiply same positions | Must be identical dimensions |
Python's NumPy uses @ for matrix multiplication and * for element-wise. Know which one you need.
Getting Started: Practice Problem
Multiply these matrices:
A = [ [1, 0, 2], [3, 1, 1] ]
B = [ [4, 2], [1, 1], [0, 3] ]
Solution:
Dimensions: (2×3) × (3×2) = (2×2) result
Element [1,1]: 1×4 + 0×1 + 2×0 = 4
Element [1,2]: 1×2 + 0×1 + 2×3 = 8
Element [2,1]: 3×4 + 1×1 + 1×0 = 13
Element [2,2]: 3×2 + 1×1 + 1×3 = 10
Result: [ [4, 8], [13, 10] ]
Check each dot product calculation before moving on. One wrong number cascades through the rest.
When You'll Actually Use This
Matrix multiplication appears in computer graphics (transformations), machine learning (neural networks), physics (coordinate transformations), and any system involving multiple linear equations. The math isn't abstract for long.