A matrix is a rectangular array of numbers arranged in rows and columns. Matrices are not just a bookkeeping tool for systems of equations — they are objects in their own right, with their own arithmetic. Matrix operations are the foundation of computer graphics, machine learning, engineering simulations, and economic modeling.
In this lesson, you will learn the rules for adding, subtracting, scaling, and multiplying matrices, including the critical fact that matrix multiplication is not commutative — the order you multiply matters.
Matrix Dimensions
A matrix with m rows and n columns is called an m×n matrix (read ”m by n”). The dimensions are always stated rows first, columns second.
A=[142536]
This is a 2×3 matrix — 2 rows, 3 columns.
Individual entries are written aij, where i is the row number and j is the column number. In the matrix above, a12=2 (row 1, column 2) and a21=4 (row 2, column 1).
Matrix Addition and Subtraction
Two matrices can be added or subtracted only if they have the same dimensions. The operation is performed entry by entry.
If A and B are both m×n matrices, then:
(A+B)ij=aij+bij
Example 1: Matrix Addition
[123−1]+[4−205]=[1+42+(−2)3+0−1+5]=[5034]
Example 2: Matrix Subtraction
[7429]−[3156]=[43−33]
Undefined operations: You cannot add a 2×3 matrix to a 3×2 matrix. The dimensions must match exactly.
Scalar Multiplication
Multiplying a matrix by a scalar (a single number) means multiplying every entry by that number.
k⋅A=[k⋅a11k⋅a21k⋅a12k⋅a22]
Example 3: Scalar Multiplication
3[20−14]=[60−312]
Example 4: Linear Combination of Matrices
Compute 2A−3B where A=[1−243] and B=[05−12].
2A=[2−486],3B=[015−36]
2A−3B=[2−0−4−158−(−3)6−6]=[2−19110]
Matrix Multiplication
Matrix multiplication is the most important — and most misunderstood — matrix operation. It is not done entry by entry.
When Is Multiplication Defined?
The product AB is defined only when the number of columns of A equals the number of rows of B.
If A is m×n and B is n×p, then AB is an m×p matrix.
m×nA⋅n×pB=m×pAB
Memory aid: The inner dimensions must match (n=n). The outer dimensions give the size of the result (m×p).
A 2×3 matrix times a 3×4 matrix gives a 2×4 matrix. A 2×3 matrix times a 2×3 matrix is undefined (3 does not equal 2).
The Row-by-Column Rule
Each entry of the product AB is computed by taking the dot product of a row of A with a column of B:
(AB)ij=∑k=1naik⋅bkj
In plain English: to find the entry in row i, column j of the product, multiply each entry in row i of A by the corresponding entry in column j of B, then add the results.
Example 5: Multiplying 2x2 Matrices
AB=[2134][50−12]
Entry (1,1): Row 1 of A dotted with Column 1 of B: 2(5)+3(0)=10
Entry (1,2): Row 1 of A dotted with Column 2 of B: 2(−1)+3(2)=4
Entry (2,1): Row 2 of A dotted with Column 1 of B: 1(5)+4(0)=5
Entry (2,2): Row 2 of A dotted with Column 2 of B: 1(−1)+4(2)=7
AB=[10547]
Example 6: Multiplying Matrices with Different Dimensions
[13012−1]4−25
A is 2×3 and B is 3×1. Inner dimensions match (3 = 3), so the product is 2×1.
Entry (1,1): 1(4)+0(−2)+2(5)=4+0+10=14
Entry (2,1): 3(4)+1(−2)+(−1)(5)=12−2−5=5
AB=[145]
Matrix Multiplication Is NOT Commutative
This is the single most important fact about matrix multiplication: in general, AB=BA.
The result is the original matrix — unchanged, as expected.
Properties of Matrix Operations
Property
Addition
Multiplication
Commutative
A+B=B+A
Not commutative: AB=BA in general
Associative
(A+B)+C=A+(B+C)
(AB)C=A(BC)
Distributive
—
A(B+C)=AB+AC
Identity
A+O=A (zero matrix)
AI=IA=A
Real-World Application: Production Cost Analysis
A factory makes two products using three raw materials. The production matrix P shows how many units of each material each product requires, and the cost vector C gives the cost per unit of each material:
P=[312412],C=583
The total material cost per product is:
PC=[3(5)+2(8)+1(3)1(5)+4(8)+2(3)]=[3443]
Product 1 costs 34 per unit in materials, and Product 2 costs 43 per unit. This is exactly how manufacturers compute costs across thousands of products and materials — as a single matrix multiplication.
Common Mistakes
Multiplying entry by entry. Matrix multiplication uses the row-by-column dot product, not entry-by-entry multiplication. The entry-by-entry product (called the Hadamard product) is a separate operation.
Assuming AB=BA. Matrix multiplication is not commutative. Always respect the order.
Ignoring dimension compatibility. Before multiplying, check that the inner dimensions match. A 2×3 times a 2×3 is undefined.
Confusing m×n with n×m. A 2×3 matrix has 2 rows and 3 columns, not the reverse. Dimensions are always rows-by-columns.
Practice Problems
Problem 1: Compute A+B where A=[14−32] and B=[5−170].
A+B=[1+54+(−1)−3+72+0]=[6342]
Answer:[6342]
Problem 2: Compute 4A where A=−20135−1.
4A=−8041220−4
Answer:−8041220−4
Problem 3: Can you multiply a 3×2 matrix by a 3×2 matrix? Explain.
No. The product AB requires the number of columns of A (which is 2) to equal the number of rows of B (which is 3). Since 2=3, the multiplication is undefined.
Problem 4: Compute the product AB where A=[1324] and B=[0−152].
Entry (1,1): 1(0)+2(−1)=−2
Entry (1,2): 1(5)+2(2)=9
Entry (2,1): 3(0)+4(−1)=−4
Entry (2,2): 3(5)+4(2)=23
AB=[−2−4923]
Answer:[−2−4923]
Problem 5: Verify that AB=BA using the matrices from Problem 4.
We already found AB=[−2−4923]. Now compute BA:
Entry (1,1): 0(1)+5(3)=15
Entry (1,2): 0(2)+5(4)=20
Entry (2,1): −1(1)+2(3)=5
Entry (2,2): −1(2)+2(4)=6
BA=[155206]
Since [−2−4923]=[155206], we confirm AB=BA.
Problem 6: Compute [20−1431]12−10−35.
A is 2×3, B is 3×2, so the product is 2×2.
Entry (1,1): 2(1)+(−1)(2)+3(−1)=2−2−3=−3
Entry (1,2): 2(0)+(−1)(−3)+3(5)=0+3+15=18
Entry (2,1): 0(1)+4(2)+1(−1)=0+8−1=7
Entry (2,2): 0(0)+4(−3)+1(5)=0−12+5=−7
AB=[−3718−7]
Answer:[−3718−7]
Key Takeaways
Matrix dimensions are always stated rows-by-columns: an m×n matrix has m rows and n columns
Addition and subtraction require identical dimensions and operate entry by entry
Scalar multiplication multiplies every entry by the scalar
Matrix multiplication uses the row-by-column dot product — it is NOT entry by entry
Multiplication AB is defined only when the number of columns of A equals the number of rows of B; the result is m×p
Matrix multiplication is not commutative: AB=BA in general
The identity matrixI satisfies AI=IA=A, making it the multiplicative identity for matrices