Matrix and vector multiplication examples

Example 1

Compute Ax where x = (-2,-1, 0)

A = ⌊             ⌋
   1    2   3
|  4    5   6 |
|⌈             |⌉
   7    8   9
  10  11   12.

Solution:

Ax = ⌊  1   2    3 ⌋
|             |
|  4   5    6 |
⌈  7   8    9 ⌉
  10  11  12⌊     ⌋
  - 2
⌈   1 ⌉
    0
= ⌊                        ⌋
    - 2 ⋅ 1 + 1 ⋅ 2 + 0 ⋅ 3
||   - 2 ⋅ 4 + 1 ⋅ 5 + 0 ⋅ 6 ||
⌈   - 2 ⋅ 7 + 1 ⋅ 8 + 0 ⋅ 9 ⌉
  - 2 ⋅ 10 + 1 ⋅ 11 + 0 ⋅ 12
= ⌊     ⌋
   0
|| - 3 ||
⌈ - 6 ⌉
  - 9 = (0,-3,-6,-6).

Example 2

Compute Ay where y = (-3,-2,-1, 0) and A is as in Example 1.

Solution: The matrix-vector product is not defined. A is 4 × 3 and y is 4 × 1 (viewed as column vector).

Example 3

Compute BC, where

B = [ 1  2  3 ]

  4  5  6 and C = ⌊       ⌋
   1  2
⌈  3  4 ⌉
   5  6.

Solution:

BC = [          ]
   1  2  3
   4  5  6⌊      ⌋
  1  2
⌈ 3  4 ⌉
  5  6
= [                                         ]
   1 ⋅ 1 + 2 ⋅ 3 + 3 ⋅ 5 1 ⋅ 2 + 2 ⋅ 4 + 3 ⋅ 6
   4 ⋅ 1 + 5 ⋅ 3 + 6 ⋅ 5 4 ⋅ 2 + 5 ⋅ 4 + 6 ⋅ 6
= [         ]
   22  28
   49  64

Example 4

Using B and C as defined in Example 3, calculate CB.

Solution:

CB = ⌊      ⌋
  1  2
⌈ 3  4 ⌉
  5  6[         ]
  1  2  3
  4  5  6
= ⌊                                         ⌋
  1 ⋅ 1 + 2 ⋅ 4  1 ⋅ 2 + 2 ⋅ 5 1 ⋅ 3 + 2 ⋅ 6
⌈ 3 ⋅ 1 + 4 ⋅ 4  3 ⋅ 2 + 4 ⋅ 5 3 ⋅ 3 + 4 ⋅ 6 ⌉
  5 ⋅ 1 + 6 ⋅ 4  5 ⋅ 2 + 6 ⋅ 5 5 ⋅ 3 + 6 ⋅ 6
= ⌊             ⌋
   9  12   15
⌈ 19  26   33 ⌉
  29  40   51
Clearly, one can see that matrix multiplication is not commutative, i.e., BCCB. In the case of examples 3 and 4, BC isn’t even the same size matrix as CB. In some other cases, BC might be defined but CB won’t be defined (for example, when B is a 3 × 2 matrix and C is a 2 × 4 matrix). It is even true that when B and C are square matrices, matrix multiplication is not commutative. You can try yourself and see that BCCB if
B = [       ]
   1  2
   3  4 and C = [      ]
  5  6
  7  8.