• Foundation
  • About 15 min
  • 5 practice questions

Adding, scaling and multiplying matrices

Add and subtract matrices of the same order, multiply a matrix by a number, multiply two matrices row by column, and see why AB and BA are usually different.

If something looks wrong, please tell us.

Matrices become useful when you can calculate with them. Addition and multiplication by a number work element by element, just as you would expect. Multiplying two matrices is different: it combines rows of the first with columns of the second. This lesson builds each operation step by step and shows the one surprise that every beginner must learn, that the order of multiplication matters.

Addition and subtraction

Two matrices can be added only if they have the same order. Add the elements in matching positions. Let A = [1 2; 3 4] and B = [2 0; 1 −1]. Then A + B = [1 + 2 2 + 0; 3 + 1 4 − 1] = [3 2; 4 3]. Subtraction is the same with minus signs. Matrices of different orders, such as a 2 × 2 and a 2 × 3, cannot be added at all.

Multiplying by a number

To multiply a matrix by a number k (a scalar), multiply every element by k. So 2A = [2 4; 6 8]. Combining the two operations: 2A − B = [2 − 2 4 − 0; 6 − 1 8 + 1] = [0 4; 5 9]. Addition of matrices is commutative (A + B = B + A) and associative, and the zero matrix O plays the role of 0: A + O = A.

Multiplying two matrices

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 has order m × p. A quick way to remember: write the orders side by side, (m × n)(n × p); the inner numbers must match and the outer numbers give the answer's order.

Each element of AB is found by taking a row of A and a column of B, multiplying their elements in pairs and adding. The element in row i and column j of AB uses row i of A and column j of B.

Worked example 1: a 2 × 2 product

With A = [1 2; 3 4] and B = [2 0; 1 −1]: Row 1 of A with column 1 of B: 1 × 2 + 2 × 1 = 4. Row 1 with column 2: 1 × 0 + 2 × (−1) = −2. Row 2 with column 1: 3 × 2 + 4 × 1 = 10. Row 2 with column 2: 3 × 0 + 4 × (−1) = −4. So AB = [4 −2; 10 −4].

Now reverse the order. BA uses rows of B with columns of A: 2 × 1 + 0 × 3 = 2, 2 × 2 + 0 × 4 = 4, 1 × 1 + (−1) × 3 = −2 and 1 × 2 + (−1) × 4 = −2. So BA = [2 4; −2 −2], which is not equal to AB. Matrix multiplication is not commutative: in general AB ≠ BA. Sometimes one product is not even defined, for example when A is 2 × 3 and B is 3 × 3: AB exists, but BA would need 3 columns in B to match 2 rows in A.

Worked example 2: a product that is not square

Multiply P = [1 0 2; −1 3 1], a 2 × 3 matrix, by Q = [2; 1; 3], a 3 × 1 matrix. The inner numbers are both 3, so PQ exists and is 2 × 1. Row 1: 1 × 2 + 0 × 1 + 2 × 3 = 8. Row 2: (−1) × 2 + 3 × 1 + 1 × 3 = 4. So PQ = [8; 4]. The product QP is not defined, because Q has 1 column and P has 2 rows.

Rules that do hold

  • Associative: (AB)C = A(BC), whenever the products are defined.
  • Distributive: A(B + C) = AB + AC and (A + B)C = AC + BC.
  • Identity: AI = IA = A for a square matrix A and the identity I of the same order.
  • Powers: A² means AA, and it is defined only for a square matrix.

AB exists only when the columns of A equal the rows of B; (m × n)(n × p) gives m × p. Each element is a row of A times a column of B, added up. In general AB ≠ BA.

— Rule to remember

Key takeaways

Check the orders before any operation: same order for addition, matching inner numbers for multiplication. Scalar multiplication multiplies every element. Multiply row by column and add. Never assume that AB equals BA; work out each product separately.

Check your understanding

  1. 1. A is a 3 × 2 matrix and B is a 2 × 4 matrix. What is the order of AB?

    1. 2 × 2
    2. 3 × 4
    3. 4 × 3
    4. AB is not defined
    Show answer

    Answer: B. The inner numbers (2 and 2) match, and the outer numbers give the order: 3 × 4.

  2. 2. A = [2 3; 1 −1] and B = [1 0; 2 4]. What is the element in row 1, column 2 of AB?

    1. 12
    2. 0
    3. 8
    4. −4
    Show answer

    Answer: A. Row 1 of A is (2, 3) and column 2 of B is (0, 4): 2 × 0 + 3 × 4 = 12.

  3. 3. A = [1 2; 0 3] and B = [2 −1; 4 1]. What is 3A − 2B?

    1. [−1 4; −8 7]
    2. [−1 8; −8 7]
    3. [1 8; 8 7]
    4. [−1 8; 8 11]
    Show answer

    Answer: B. 3A = [3 6; 0 9] and 2B = [4 −2; 8 2]. Subtract: [3 − 4 6 + 2; 0 − 8 9 − 2] = [−1 8; −8 7].

  4. 4. A is 2 × 3 and B is 3 × 3. Which statement is true?

    1. BA is defined but AB is not
    2. Both AB and BA are defined
    3. Neither AB nor BA is defined
    4. AB is defined but BA is not
    Show answer

    Answer: D. AB: (2 × 3)(3 × 3), inner numbers match, so it exists. BA: (3 × 3)(2 × 3), inner numbers 3 and 2 differ, so it does not.

  5. 5. If 2X + A = B, where A = [1 3; 5 7] and B = [3 1; 1 −1], what is X?

    1. [2 −2; −4 −8]
    2. [2 2; 3 3]
    3. [1 1; −2 −4]
    4. [1 −1; −2 −4]
    Show answer

    Answer: D. 2X = B − A = [2 −2; −4 −8], so X = [1 −1; −2 −4].

Privacy · Terms · Refunds · Delivery