College Algebra

Matrix Operations

Last updated: March 2026 · Advanced
Before you start

You should be comfortable with:

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 mm rows and nn columns is called an m×nm \times n matrix (read ”mm by nn”). The dimensions are always stated rows first, columns second.

A=[123456]A = \begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \end{bmatrix}

This is a 2×32 \times 3 matrix — 2 rows, 3 columns.

Individual entries are written aija_{ij}, where ii is the row number and jj is the column number. In the matrix above, a12=2a_{12} = 2 (row 1, column 2) and a21=4a_{21} = 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 AA and BB are both m×nm \times n matrices, then:

(A+B)ij=aij+bij(A + B)_{ij} = a_{ij} + b_{ij}

Example 1: Matrix Addition

[1321]+[4025]=[1+43+02+(2)1+5]=[5304]\begin{bmatrix} 1 & 3 \\ 2 & -1 \end{bmatrix} + \begin{bmatrix} 4 & 0 \\ -2 & 5 \end{bmatrix} = \begin{bmatrix} 1+4 & 3+0 \\ 2+(-2) & -1+5 \end{bmatrix} = \begin{bmatrix} 5 & 3 \\ 0 & 4 \end{bmatrix}

Example 2: Matrix Subtraction

[7249][3516]=[4333]\begin{bmatrix} 7 & 2 \\ 4 & 9 \end{bmatrix} - \begin{bmatrix} 3 & 5 \\ 1 & 6 \end{bmatrix} = \begin{bmatrix} 4 & -3 \\ 3 & 3 \end{bmatrix}

Undefined operations: You cannot add a 2×32 \times 3 matrix to a 3×23 \times 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.

kA=[ka11ka12ka21ka22]k \cdot A = \begin{bmatrix} k \cdot a_{11} & k \cdot a_{12} \\ k \cdot a_{21} & k \cdot a_{22} \end{bmatrix}

Example 3: Scalar Multiplication

3[2104]=[63012]3 \begin{bmatrix} 2 & -1 \\ 0 & 4 \end{bmatrix} = \begin{bmatrix} 6 & -3 \\ 0 & 12 \end{bmatrix}

Example 4: Linear Combination of Matrices

Compute 2A3B2A - 3B where A=[1423]A = \begin{bmatrix} 1 & 4 \\ -2 & 3 \end{bmatrix} and B=[0152]B = \begin{bmatrix} 0 & -1 \\ 5 & 2 \end{bmatrix}.

2A=[2846],3B=[03156]2A = \begin{bmatrix} 2 & 8 \\ -4 & 6 \end{bmatrix}, \quad 3B = \begin{bmatrix} 0 & -3 \\ 15 & 6 \end{bmatrix}

2A3B=[208(3)41566]=[211190]2A - 3B = \begin{bmatrix} 2-0 & 8-(-3) \\ -4-15 & 6-6 \end{bmatrix} = \begin{bmatrix} 2 & 11 \\ -19 & 0 \end{bmatrix}

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 ABAB is defined only when the number of columns of AA equals the number of rows of BB.

If AA is m×nm \times n and BB is n×pn \times p, then ABAB is an m×pm \times p matrix.

Am×nBn×p=ABm×p\underset{m \times n}{A} \cdot \underset{n \times p}{B} = \underset{m \times p}{AB}

Memory aid: The inner dimensions must match (n=nn = n). The outer dimensions give the size of the result (m×pm \times p).

A 2×32 \times 3 matrix times a 3×43 \times 4 matrix gives a 2×42 \times 4 matrix. A 2×32 \times 3 matrix times a 2×32 \times 3 matrix is undefined (3 does not equal 2).

The Row-by-Column Rule

Each entry of the product ABAB is computed by taking the dot product of a row of AA with a column of BB:

(AB)ij=k=1naikbkj(AB)_{ij} = \sum_{k=1}^{n} a_{ik} \cdot b_{kj}

In plain English: to find the entry in row ii, column jj of the product, multiply each entry in row ii of AA by the corresponding entry in column jj of BB, then add the results.

Example 5: Multiplying 2x2 Matrices

AB=[2314][5102]AB = \begin{bmatrix} 2 & 3 \\ 1 & 4 \end{bmatrix} \begin{bmatrix} 5 & -1 \\ 0 & 2 \end{bmatrix}

Entry (1,1)(1,1): Row 1 of AA dotted with Column 1 of BB: 2(5)+3(0)=102(5) + 3(0) = 10

Entry (1,2)(1,2): Row 1 of AA dotted with Column 2 of BB: 2(1)+3(2)=42(-1) + 3(2) = 4

Entry (2,1)(2,1): Row 2 of AA dotted with Column 1 of BB: 1(5)+4(0)=51(5) + 4(0) = 5

Entry (2,2)(2,2): Row 2 of AA dotted with Column 2 of BB: 1(1)+4(2)=71(-1) + 4(2) = 7

AB=[10457]AB = \begin{bmatrix} 10 & 4 \\ 5 & 7 \end{bmatrix}

Example 6: Multiplying Matrices with Different Dimensions

[102311][425]\begin{bmatrix} 1 & 0 & 2 \\ 3 & 1 & -1 \end{bmatrix} \begin{bmatrix} 4 \\ -2 \\ 5 \end{bmatrix}

AA is 2×32 \times 3 and BB is 3×13 \times 1. Inner dimensions match (3 = 3), so the product is 2×12 \times 1.

Entry (1,1)(1,1): 1(4)+0(2)+2(5)=4+0+10=141(4) + 0(-2) + 2(5) = 4 + 0 + 10 = 14

Entry (2,1)(2,1): 3(4)+1(2)+(1)(5)=1225=53(4) + 1(-2) + (-1)(5) = 12 - 2 - 5 = 5

AB=[145]AB = \begin{bmatrix} 14 \\ 5 \end{bmatrix}

Matrix Multiplication Is NOT Commutative

This is the single most important fact about matrix multiplication: in general, ABBAAB \neq BA.

Consider A=[1201]A = \begin{bmatrix} 1 & 2 \\ 0 & 1 \end{bmatrix} and B=[0110]B = \begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}.

AB=[1(0)+2(1)1(1)+2(0)0(0)+1(1)0(1)+1(0)]=[2110]AB = \begin{bmatrix} 1(0)+2(1) & 1(1)+2(0) \\ 0(0)+1(1) & 0(1)+1(0) \end{bmatrix} = \begin{bmatrix} 2 & 1 \\ 1 & 0 \end{bmatrix}

BA=[0(1)+1(0)0(2)+1(1)1(1)+0(0)1(2)+0(1)]=[0112]BA = \begin{bmatrix} 0(1)+1(0) & 0(2)+1(1) \\ 1(1)+0(0) & 1(2)+0(1) \end{bmatrix} = \begin{bmatrix} 0 & 1 \\ 1 & 2 \end{bmatrix}

ABBAAB \neq BA. In some cases, ABAB might be defined but BABA might not even exist (if the dimensions are incompatible in the reverse order).

The Identity Matrix

The identity matrix InI_n is the n×nn \times n matrix with 1s on the diagonal and 0s everywhere else:

I2=[1001],I3=[100010001]I_2 = \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix}, \quad I_3 = \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix}

The identity matrix is the matrix equivalent of the number 1:

AI=AandIA=AAI = A \quad \text{and} \quad IA = A

for any matrix AA where the dimensions are compatible.

Example 7: Multiplying by the Identity Matrix

[3275][1001]=[3(1)+(2)(0)3(0)+(2)(1)7(1)+5(0)7(0)+5(1)]=[3275]\begin{bmatrix} 3 & -2 \\ 7 & 5 \end{bmatrix} \begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix} = \begin{bmatrix} 3(1)+(-2)(0) & 3(0)+(-2)(1) \\ 7(1)+5(0) & 7(0)+5(1) \end{bmatrix} = \begin{bmatrix} 3 & -2 \\ 7 & 5 \end{bmatrix}

The result is the original matrix — unchanged, as expected.

Properties of Matrix Operations

PropertyAdditionMultiplication
CommutativeA+B=B+AA + B = B + ANot commutative: ABBAAB \neq BA in general
Associative(A+B)+C=A+(B+C)(A + B) + C = A + (B + C)(AB)C=A(BC)(AB)C = A(BC)
DistributiveA(B+C)=AB+ACA(B + C) = AB + AC
IdentityA+O=AA + O = A (zero matrix)AI=IA=AAI = IA = A

Real-World Application: Production Cost Analysis

A factory makes two products using three raw materials. The production matrix PP shows how many units of each material each product requires, and the cost vector CC gives the cost per unit of each material:

P=[321142],C=[583]P = \begin{bmatrix} 3 & 2 & 1 \\ 1 & 4 & 2 \end{bmatrix}, \quad C = \begin{bmatrix} 5 \\ 8 \\ 3 \end{bmatrix}

The total material cost per product is:

PC=[3(5)+2(8)+1(3)1(5)+4(8)+2(3)]=[3443]PC = \begin{bmatrix} 3(5) + 2(8) + 1(3) \\ 1(5) + 4(8) + 2(3) \end{bmatrix} = \begin{bmatrix} 34 \\ 43 \end{bmatrix}

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

  1. 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.
  2. Assuming AB=BAAB = BA. Matrix multiplication is not commutative. Always respect the order.
  3. Ignoring dimension compatibility. Before multiplying, check that the inner dimensions match. A 2×32 \times 3 times a 2×32 \times 3 is undefined.
  4. Confusing m×nm \times n with n×mn \times m. A 2×32 \times 3 matrix has 2 rows and 3 columns, not the reverse. Dimensions are always rows-by-columns.

Practice Problems

Problem 1: Compute A+BA + B where A=[1342]A = \begin{bmatrix} 1 & -3 \\ 4 & 2 \end{bmatrix} and B=[5710]B = \begin{bmatrix} 5 & 7 \\ -1 & 0 \end{bmatrix}.

A+B=[1+53+74+(1)2+0]=[6432]A + B = \begin{bmatrix} 1+5 & -3+7 \\ 4+(-1) & 2+0 \end{bmatrix} = \begin{bmatrix} 6 & 4 \\ 3 & 2 \end{bmatrix}

Answer: [6432]\begin{bmatrix} 6 & 4 \\ 3 & 2 \end{bmatrix}

Problem 2: Compute 4A4A where A=[230511]A = \begin{bmatrix} -2 & 3 \\ 0 & 5 \\ 1 & -1 \end{bmatrix}.

4A=[81202044]4A = \begin{bmatrix} -8 & 12 \\ 0 & 20 \\ 4 & -4 \end{bmatrix}

Answer: [81202044]\begin{bmatrix} -8 & 12 \\ 0 & 20 \\ 4 & -4 \end{bmatrix}

Problem 3: Can you multiply a 3×23 \times 2 matrix by a 3×23 \times 2 matrix? Explain.

No. The product ABAB requires the number of columns of AA (which is 2) to equal the number of rows of BB (which is 3). Since 232 \neq 3, the multiplication is undefined.

Problem 4: Compute the product ABAB where A=[1234]A = \begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix} and B=[0512]B = \begin{bmatrix} 0 & 5 \\ -1 & 2 \end{bmatrix}.

Entry (1,1)(1,1): 1(0)+2(1)=21(0) + 2(-1) = -2

Entry (1,2)(1,2): 1(5)+2(2)=91(5) + 2(2) = 9

Entry (2,1)(2,1): 3(0)+4(1)=43(0) + 4(-1) = -4

Entry (2,2)(2,2): 3(5)+4(2)=233(5) + 4(2) = 23

AB=[29423]AB = \begin{bmatrix} -2 & 9 \\ -4 & 23 \end{bmatrix}

Answer: [29423]\begin{bmatrix} -2 & 9 \\ -4 & 23 \end{bmatrix}

Problem 5: Verify that ABBAAB \neq BA using the matrices from Problem 4.

We already found AB=[29423]AB = \begin{bmatrix} -2 & 9 \\ -4 & 23 \end{bmatrix}. Now compute BABA:

Entry (1,1)(1,1): 0(1)+5(3)=150(1) + 5(3) = 15

Entry (1,2)(1,2): 0(2)+5(4)=200(2) + 5(4) = 20

Entry (2,1)(2,1): 1(1)+2(3)=5-1(1) + 2(3) = 5

Entry (2,2)(2,2): 1(2)+2(4)=6-1(2) + 2(4) = 6

BA=[152056]BA = \begin{bmatrix} 15 & 20 \\ 5 & 6 \end{bmatrix}

Since [29423][152056]\begin{bmatrix} -2 & 9 \\ -4 & 23 \end{bmatrix} \neq \begin{bmatrix} 15 & 20 \\ 5 & 6 \end{bmatrix}, we confirm ABBAAB \neq BA.

Problem 6: Compute [213041][102315]\begin{bmatrix} 2 & -1 & 3 \\ 0 & 4 & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 \\ 2 & -3 \\ -1 & 5 \end{bmatrix}.

AA is 2×32 \times 3, BB is 3×23 \times 2, so the product is 2×22 \times 2.

Entry (1,1)(1,1): 2(1)+(1)(2)+3(1)=223=32(1) + (-1)(2) + 3(-1) = 2 - 2 - 3 = -3

Entry (1,2)(1,2): 2(0)+(1)(3)+3(5)=0+3+15=182(0) + (-1)(-3) + 3(5) = 0 + 3 + 15 = 18

Entry (2,1)(2,1): 0(1)+4(2)+1(1)=0+81=70(1) + 4(2) + 1(-1) = 0 + 8 - 1 = 7

Entry (2,2)(2,2): 0(0)+4(3)+1(5)=012+5=70(0) + 4(-3) + 1(5) = 0 - 12 + 5 = -7

AB=[31877]AB = \begin{bmatrix} -3 & 18 \\ 7 & -7 \end{bmatrix}

Answer: [31877]\begin{bmatrix} -3 & 18 \\ 7 & -7 \end{bmatrix}

Key Takeaways

  • Matrix dimensions are always stated rows-by-columns: an m×nm \times n matrix has mm rows and nn 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 ABAB is defined only when the number of columns of AA equals the number of rows of BB; the result is m×pm \times p
  • Matrix multiplication is not commutative: ABBAAB \neq BA in general
  • The identity matrix II satisfies AI=IA=AAI = IA = A, making it the multiplicative identity for matrices

Return to College Algebra for more topics in this section.

Last updated: March 29, 2026