Skip to content
VidiMaster it, module by module
Module 1/Matrices

Matrix Operations

Matrices can be added, scaled, and multiplied, but the rules are not the ones from ordinary arithmetic. This lesson covers entrywise addition and scalar multiplication, the dimension rule and row-by-column recipe for matrix multiplication, and why ABAB and BABA usually differ.

Before you start — give these a try

Attempting first primes your brain for the lesson — even if you miss. Nothing is graded or saved; it's just a warm-up.

Compute the product ABAB where A=[1231]A=\begin{bmatrix} 1 & 2 \\ 3 & 1 \end{bmatrix} and B=[2014]B=\begin{bmatrix} 2 & 0 \\ 1 & 4 \end{bmatrix}.

Let A=[2−13041]A=\begin{bmatrix} 2 & -1 & 3 \\ 0 & 4 & 1 \end{bmatrix} and B=[120−153]B=\begin{bmatrix} 1 & 2 \\ 0 & -1 \\ 5 & 3 \end{bmatrix}. Compute the single entry (AB)12(AB)_{12} (row 11, column 22).

What you’ll be able to do

  • Add and subtract two matrices of the same shape by operating entrywise.
  • Compute a scalar multiple cAcA by scaling every entry of AA.
  • Use the dimension rule to decide whether a product ABAB is defined and to predict its shape.
  • Evaluate matrix products with the row-by-column rule, including any single entry (AB)ij(AB)_{ij}.
  • Explain why matrix multiplication is not commutative and describe the role of the identity matrix InI_n.

In your course

· MATH2015 · Linear Algebra & Probability
§4.2 Composition and matrix multiplication§4.4 Operations with matrices
  • Definition 4.3Entrywise sum and scalar multiple
  • Theorem 4.3Rules of matrix algebra
    A+B=B+AA+B=B+A, (A+B)C=AC+BC(A+B)C=AC+BC, A(B+C)=AB+ACA(B+C)=AB+AC, (AB)C=A(BC)(AB)C=A(BC) — but AB≠BAAB\neq BA in general.
  • Remark 4.2Multiplication = composition, non-commutative
1

Matrices, addition, and scalar multiplication

What a matrix is. A matrix is a rectangular grid of numbers. We say a matrix is m×nm \times n (read "mm by nn") when it has mm rows and nn columns; the pair (m,n)(m,n) is its shape (or dimension). We write A=(aij)A=(a_{ij}), where the entry aija_{ij} is the number in row ii, column jj (rows and columns are numbered starting at 11). For example, A=[1203−14]A=\begin{bmatrix} 1 & 2 & 0 \\ 3 & -1 & 4 \end{bmatrix} is 2×32\times 3, and a23=4a_{23}=4.

Addition (same shape, entrywise). You may add two matrices only when they have the same shape. Then A+BA+B is formed by adding corresponding entries: (A+B)ij=aij+bij.(A+B)_{ij}=a_{ij}+b_{ij}. Subtraction works the same way. If the shapes differ, A+BA+B is simply undefined.

Scalar multiplication (entrywise). A scalar is just a number cc. The scalar multiple cAcA scales every entry: (cA)ij=c aij.(cA)_{ij}=c\,a_{ij}. For instance, 2[1−305]=[2−6010]2\begin{bmatrix} 1 & -3 \\ 0 & 5 \end{bmatrix}=\begin{bmatrix} 2 & -6 \\ 0 & 10 \end{bmatrix}.

Useful facts. Addition is commutative and associative: A+B=B+AA+B=B+A and (A+B)+C=A+(B+C)(A+B)+C=A+(B+C). Scalars distribute over sums: c(A+B)=cA+cBc(A+B)=cA+cB. These all hold because every rule is applied one entry at a time, where ordinary number arithmetic already obeys them.

2

Matrix multiplication: the dimension rule and row-by-column

When is ABAB defined? Unlike addition, multiplication does not require equal shapes. Instead it uses the dimension rule: if AA is m×nm\times n and BB is n×pn\times p — that is, the number of columns of AA equals the number of rows of BB — then ABAB is defined and has shape m×pm\times p: (m×n⏟A) (n×p⏟B)=m×p⏟AB.(\underbrace{m\times n}_{A})\,(\underbrace{n\times p}_{B})=\underbrace{m\times p}_{AB}. The two inner numbers must match; the two outer numbers give the result's shape. If the inner numbers disagree, ABAB is undefined.

The row-by-column rule. The entry in row ii, column jj of ABAB is the dot product of row ii of AA with column jj of BB: (AB)ij=∑k=1naik bkj=ai1b1j+ai2b2j+⋯+ainbnj.(AB)_{ij}=\sum_{k=1}^{n} a_{ik}\,b_{kj}=a_{i1}b_{1j}+a_{i2}b_{2j}+\cdots+a_{in}b_{nj}. Here the index kk runs across the shared dimension nn. Concretely, to get the top-left entry you slide row 11 of AA across column 11 of BB, multiply matching pairs, and add them up.

A quick computation. With A=[1203],B=[4125],A=\begin{bmatrix} 1 & 2 \\ 0 & 3 \end{bmatrix},\qquad B=\begin{bmatrix} 4 & 1 \\ 2 & 5 \end{bmatrix}, the (1,1)(1,1) entry is 1⋅4+2⋅2=81\cdot 4 + 2\cdot 2 = 8 and the (2,2)(2,2) entry is 0⋅1+3⋅5=150\cdot 1 + 3\cdot 5 = 15. Filling in all four entries, AB=[811615].AB=\begin{bmatrix} 8 & 11 \\ 6 & 15 \end{bmatrix}.

3

Non-commutativity and the identity matrix

Order matters. For ordinary numbers xy=yxxy=yx, but for matrices ABAB and BABA are usually different — matrix multiplication is non-commutative. Sometimes only one of the two products is even defined (the dimension rule can fail in the opposite order), and sometimes both are defined but give different results or even different shapes. For example, with A=[1234],B=[0110],A=\begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix},\qquad B=\begin{bmatrix} 0 & 1 \\ 1 & 0 \end{bmatrix}, we get AB=[2143]AB=\begin{bmatrix} 2 & 1 \\ 4 & 3 \end{bmatrix} while BA=[3412]BA=\begin{bmatrix} 3 & 4 \\ 1 & 2 \end{bmatrix}. Since AB≠BAAB\neq BA, the blanket claim "AB=BAAB=BA" is false in general.

The identity matrix. The n×nn\times n identity matrix InI_n has 11s on the main diagonal and 00s everywhere else, e.g. I2=[1001]I_2=\begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix}. It behaves like the number 11 for multiplication: for every m×nm\times n matrix AA, A In=AandIm A=A.A\,I_n=A\qquad\text{and}\qquad I_m\,A=A. So multiplying by II leaves a matrix unchanged — one of the few places where matrix multiplication is pleasantly simple.

Dimension Rule for Matrix Multiplication

If AA is m×nm\times n and BB is n×pn\times p, then the product ABAB is defined and is an m×pm\times p matrix. If the number of columns of AA does not equal the number of rows of BB, then ABAB is undefined.

Intuition. A row of AA and a column of BB must have the same length to be paired up and summed; that shared length is the inner dimension nn. The leftover outer dimensions mm and pp become the size of the answer.
Entry Formula for Matrix Multiplication

For AA (m×nm\times n) and BB (n×pn\times p), the (i,j)(i,j) entry of the product is (AB)ij=∑k=1naikbkj(AB)_{ij}=\sum_{k=1}^{n} a_{ik}b_{kj}, the dot product of row ii of AA with column jj of BB.

Intuition. Each output entry blends one full row of AA with one full column of BB. You march the index kk across the shared dimension, multiplying matching entries and accumulating the total.
Identity Matrix Property

Let InI_n be the n×nn\times n matrix with 11s on the main diagonal and 00s elsewhere. For any m×nm\times n matrix AA, we have AIn=AAI_n=A and ImA=AI_mA=A.

Intuition. The identity acts like the number 11: in the row-by-column sum, exactly one term survives — the one hitting the diagonal 11 — and it reproduces the original entry unchanged.

Worked examples

Example 1

Let A=[1234]A=\begin{bmatrix} 1 & 2 \\ 3 & 4 \end{bmatrix} and B=[5678]B=\begin{bmatrix} 5 & 6 \\ 7 & 8 \end{bmatrix}. Compute A+BA+B, 3A3A, and the product ABAB. Then compute BABA and compare it with ABAB.

  1. 1

    Check shapes. Both AA and BB are 2×22\times 2, so they are the same shape — addition is allowed — and the inner dimensions match for multiplication (2=22=2), so ABAB is defined and will be 2×22\times 2.

  2. 2

    Add entrywise. Add corresponding entries: A+B=[1+52+63+74+8]=[681012]A+B=\begin{bmatrix} 1+5 & 2+6 \\ 3+7 & 4+8 \end{bmatrix}=\begin{bmatrix} 6 & 8 \\ 10 & 12 \end{bmatrix}.

  3. 3

    Scale entrywise. Multiply every entry of AA by 33: 3A=[3⋅13⋅23⋅33⋅4]=[36912]3A=\begin{bmatrix} 3\cdot 1 & 3\cdot 2 \\ 3\cdot 3 & 3\cdot 4 \end{bmatrix}=\begin{bmatrix} 3 & 6 \\ 9 & 12 \end{bmatrix}.

  4. 4

    Multiply, one entry at a time. Use (AB)ij=∑kaikbkj(AB)_{ij}=\sum_k a_{ik}b_{kj}. Top-left: row 11 of AA is (1,2)(1,2), column 11 of BB is (5,7)(5,7), so (AB)11=1⋅5+2⋅7=19(AB)_{11}=1\cdot 5+2\cdot 7=19. Top-right: (AB)12=1⋅6+2⋅8=22(AB)_{12}=1\cdot 6+2\cdot 8=22. Bottom-left: (AB)21=3⋅5+4⋅7=43(AB)_{21}=3\cdot 5+4\cdot 7=43. Bottom-right: (AB)22=3⋅6+4⋅8=50(AB)_{22}=3\cdot 6+4\cdot 8=50.

  5. 5

    Assemble ABAB. AB=[19224350]AB=\begin{bmatrix} 19 & 22 \\ 43 & 50 \end{bmatrix}.

  6. 6

    Compute BABA and compare. Repeating the rule with the factors swapped gives BA=[5⋅1+6⋅35⋅2+6⋅47⋅1+8⋅37⋅2+8⋅4]=[23343146]BA=\begin{bmatrix} 5\cdot1+6\cdot3 & 5\cdot2+6\cdot4 \\ 7\cdot1+8\cdot3 & 7\cdot2+8\cdot4 \end{bmatrix}=\begin{bmatrix} 23 & 34 \\ 31 & 46 \end{bmatrix}. Since [19224350]≠[23343146]\begin{bmatrix} 19 & 22 \\ 43 & 50 \end{bmatrix}\neq\begin{bmatrix} 23 & 34 \\ 31 & 46 \end{bmatrix}, we confirm AB≠BAAB\neq BA: order matters.

Answer. A+B=[681012]A+B=\begin{bmatrix} 6 & 8 \\ 10 & 12 \end{bmatrix},   3A=[36912]\;3A=\begin{bmatrix} 3 & 6 \\ 9 & 12 \end{bmatrix},   AB=[19224350]\;AB=\begin{bmatrix} 19 & 22 \\ 43 & 50 \end{bmatrix}, and BA=[23343146]≠ABBA=\begin{bmatrix} 23 & 34 \\ 31 & 46 \end{bmatrix}\neq AB.
Example 2

Let A=[102−131]A=\begin{bmatrix} 1 & 0 & 2 \\ -1 & 3 & 1 \end{bmatrix} (which is 2×32\times 3) and B=[412005]B=\begin{bmatrix} 4 & 1 \\ 2 & 0 \\ 0 & 5 \end{bmatrix} (which is 3×23\times 2). Is ABAB defined? If so, compute it.

Example 3

Let A=[7−251]A=\begin{bmatrix} 7 & -2 \\ 5 & 1 \end{bmatrix}. Verify that I2A=AI_2 A = A, where I2=[1001]I_2=\begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix}.