TExcelTAD
Home › Linear Algebra & Matrix Theory › Scalar Multiplication of Matrices

Scalar Multiplication of Matrices

Multiplying a matrix by a number (a scalar) multiplies every entry by that number. Together with addition, it lets us form linear combinations of matrices, and it follows the same distributive laws as scalar multiplication of vectors.

The definition

For a scalar cc and an m×nm \times n matrix A=[aij]A = [a_{ij}],

cA=[c⋅aij](same size m×n)cA = [c \cdot a_{ij}] \qquad (\text{same size } m \times n)
3⋅[2−104]=[6−3012]3 \cdot \begin{bmatrix} 2 & -1 \\ 0 & 4 \end{bmatrix} = \begin{bmatrix} 6 & -3 \\ 0 & 12 \end{bmatrix}

Special cases: 1⋅A=A1 \cdot A = A, 0⋅A=00 \cdot A = 0 (the zero matrix), and (−1)⋅A=−A(-1) \cdot A = -A. Dividing by a non-zero number means multiplying by its reciprocal: A/4=(14)AA/4 = \left(\frac{1}{4}\right)A.

This is exactly how scalars act on vectors in Scalar Multiplication. In fact an m×nm \times n matrix behaves, for addition and scaling, just like a vector with m⋅nm \cdot n components written in a grid.

The laws

For scalars c,dc, d and matrices A,BA, B of the same size:

Law Statement
Distributive over matrix addition c(A+B)=cA+cBc(A + B) = cA + cB
Distributive over scalar addition (c+d)A=cA+dA(c + d)A = cA + dA
Associative c(dA)=(cd)Ac(dA) = (cd)A
Identity 1A=A1A = A
Zero 0A=00A = 0 and c0=0c0 = 0

Each follows by looking at a single entry, for example (c(A+B))ij=c(aij+bij)=c⋅aij+c⋅bij=(cA+cB)ij(c(A + B))_{ij} = c(a_{ij} + b_{ij}) = c \cdot a_{ij} + c \cdot b_{ij} = (cA + cB)_{ij}.

Together with the laws of addition, these properties are the axioms of a vector space, which is why the set of all m×nm \times n matrices is itself a vector space; see Definition of Vector Spaces.

Linear combinations of matrices

A linear combination of matrices A1,…,AkA_1, \ldots, A_k is c1A1+c2A2+⋯+ckAkc_1A_1 + c_2A_2 + \cdots + c_kA_k. Every 2×22 \times 2 matrix is a linear combination of the four "unit" matrices E11,E12,E21,E22E_{11}, E_{12}, E_{21}, E_{22} (a single 1, zeros elsewhere):

[abcd]=a⋅E11+b⋅E12+c⋅E21+d⋅E22\begin{bmatrix} a & b \\ c & d \end{bmatrix} = a \cdot E_{11} + b \cdot E_{12} + c \cdot E_{21} + d \cdot E_{22}

Exact arithmetic with fractions keeps these computations clean:

python · try it yourself
from sympy import Matrix, Rational

A = Matrix([[2, -1], [0, 4]])
B = Matrix([[1, 3], [-2, 5]])

print("3A          =", (3 * A).tolist())
print("A/4         =", (A / 4).tolist())
print("2A - 3B     =", (2 * A - 3 * B).tolist())
print("c(A+B)==cA+cB:", Rational(2, 3) * (A + B) == Rational(2, 3) * A + Rational(2, 3) * B)

E11, E12 = Matrix([[1, 0], [0, 0]]), Matrix([[0, 1], [0, 0]])
E21, E22 = Matrix([[0, 0], [1, 0]]), Matrix([[0, 0], [0, 1]])
M = Matrix([[7, -2], [5, 9]])
print("rebuilt from E's:", 7 * E11 - 2 * E12 + 5 * E21 + 9 * E22 == M)
3A          = [[6, -3], [0, 12]]
A/4         = [[1/2, -1/4], [0, 1]]
2A - 3B     = [[1, -11], [6, -7]]
c(A+B)==cA+cB: True
rebuilt from E's: True

Solving equations with scalars

The laws let you rearrange matrix equations like number equations. For example 3X−A=2B3X - A = 2B gives 3X=A+2B3X = A + 2B and so X=(13)(A+2B)X = \left(\frac{1}{3}\right)(A + 2B).

python · try it yourself
from sympy import Matrix

A = Matrix([[1, 4], [-2, 0]])
B = Matrix([[1, -2], [4, 3]])
X = (A + 2 * B) / 3
print("X =", X.tolist())
print("check 3X - A == 2B:", 3 * X - A == 2 * B)
X = [[1, 0], [2, 2]]
check 3X - A == 2B: True

In software

  • Gradient descent: the weight update W←W−η⋅GW \leftarrow W - \eta \cdot G is a scalar multiple (learning rate η\eta times the gradient matrix GG) followed by a subtraction. Every optimizer step in deep learning is built from these two operations (gradient descent).
  • Blending and interpolation: (1−t)A+tB(1 - t)A + tB blends two images, two heightmaps or two sets of weights (model "soups" average network weights). It is a linear combination with weights adding to 1.
  • But blending rotation matrices is wrong: the average of two rotation matrices is generally not a rotation; it shrinks the object. Games interpolate rotations with quaternions instead (Slerp).
python · try it yourself
import numpy as np

def rot(deg):
    t = np.radians(deg)
    return np.array([[np.cos(t), -np.sin(t)], [np.sin(t), np.cos(t)]])

M = 0.5 * rot(0) + 0.5 * rot(120)          # "halfway" between 0° and 120°
v = M @ np.array([1.0, 0.0])
print("length of rotated unit vector:", round(float(np.linalg.norm(v)), 4))
print("a real rotation keeps length 1:", round(float(np.linalg.norm(rot(60) @ [1, 0])), 4))
length of rotated unit vector: 0.5
a real rotation keeps length 1: 1.0

(The @ operator is matrix multiplication, the topic of the next lesson.)

Exercises

Exercise 1: Scale and combine

With A=[10−2314]A = \begin{bmatrix} 1 & 0 & -2 \\ 3 & 1 & 4 \end{bmatrix} and B=[021−110]B = \begin{bmatrix} 0 & 2 & 1 \\ -1 & 1 & 0 \end{bmatrix}, compute −2A-2A and A+3BA + 3B.

Answer

−2A=[−204−6−2−8]-2A = \begin{bmatrix} -2 & 0 & 4 \\ -6 & -2 & -8 \end{bmatrix}; A+3B=[161044]A + 3B = \begin{bmatrix} 1 & 6 & 1 \\ 0 & 4 & 4 \end{bmatrix}.

Solution
−2A: multiply each entry by −2→[−204−6−2−8]3B=[063−330]A+3B=[1+00+6−2+33−31+34+0]=[161044]\begin{aligned} -2A&\text{: multiply each entry by } -2 \to \begin{bmatrix} -2 & 0 & 4 \\ -6 & -2 & -8 \end{bmatrix} \\ 3B &= \begin{bmatrix} 0 & 6 & 3 \\ -3 & 3 & 0 \end{bmatrix} \\ A + 3B &= \begin{bmatrix} 1 + 0 & 0 + 6 & -2 + 3 \\ 3 - 3 & 1 + 3 & 4 + 0 \end{bmatrix} = \begin{bmatrix} 1 & 6 & 1 \\ 0 & 4 & 4 \end{bmatrix} \end{aligned}

Exercise 2: Solve a matrix equation

Solve 2X+A=5X−B2X + A = 5X - B for XX, where A=[306−3]A = \begin{bmatrix} 3 & 0 \\ 6 & -3 \end{bmatrix} and B=[0339]B = \begin{bmatrix} 0 & 3 \\ 3 & 9 \end{bmatrix}.

Answer

X=[1132]X = \begin{bmatrix} 1 & 1 \\ 3 & 2 \end{bmatrix}.

Solution
2X+A=5X−B → A+B=3X → X=(A+B)/3A+B=[3396] → X=[1132]\begin{aligned} &2X + A = 5X - B \ \to\ A + B = 3X \ \to\ X = (A + B)/3 \\ &A + B = \begin{bmatrix} 3 & 3 \\ 9 & 6 \end{bmatrix} \ \to\ X = \begin{bmatrix} 1 & 1 \\ 3 & 2 \end{bmatrix} \end{aligned}
python · try it yourself
from sympy import Matrix
A = Matrix([[3, 0], [6, -3]]); B = Matrix([[0, 3], [3, 9]])
X = (A + B) / 3
print(X.tolist(), 2*X + A == 5*X - B)
[[1, 1], [3, 2]] True

Exercise 3: Find the coefficients

Find scalars x,yx, y with x⋅[1201]+y⋅[2−130]=[4332]x \cdot \begin{bmatrix} 1 & 2 \\ 0 & 1 \end{bmatrix} + y \cdot \begin{bmatrix} 2 & -1 \\ 3 & 0 \end{bmatrix} = \begin{bmatrix} 4 & 3 \\ 3 & 2 \end{bmatrix}.

Answer

x=2x = 2, y=1y = 1.

Solution

Compare entries: (1,1)(1,1): x+2y=4x + 2y = 4; (1,2)(1,2): 2x−y=32x - y = 3; (2,1)(2,1): 3y=33y = 3; (2,2)(2,2): x=2x = 2. So y=1y = 1, x=2x = 2, and both remaining equations check: 2+2=42 + 2 = 4, 4−1=34 - 1 = 3.

Exercise 4: One SGD step

A 2×22 \times 2 weight matrix W=[0.5−0.20.10.8]W = \begin{bmatrix} 0.5 & -0.2 \\ 0.1 & 0.8 \end{bmatrix} has gradient G=[1.00.0−2.00.5]G = \begin{bmatrix} 1.0 & 0.0 \\ -2.0 & 0.5 \end{bmatrix}. Compute the updated weights W−0.1⋅GW - 0.1 \cdot G in NumPy and print them rounded to 2 decimals.

Answer

[0.4−0.20.30.75]\begin{bmatrix} 0.4 & -0.2 \\ 0.3 & 0.75 \end{bmatrix}.

Solution

0.1⋅G=[0.10−0.20.05]0.1 \cdot G = \begin{bmatrix} 0.1 & 0 \\ -0.2 & 0.05 \end{bmatrix}, and subtracting gives [0.4−0.20.30.75]\begin{bmatrix} 0.4 & -0.2 \\ 0.3 & 0.75 \end{bmatrix}.

python · try it yourself
import numpy as np
W = np.array([[0.5, -0.2], [0.1, 0.8]])
G = np.array([[1.0, 0.0], [-2.0, 0.5]])
print(np.round(W - 0.1 * G, 2).tolist())
[[0.4, -0.2], [0.3, 0.75]]

Test yourself

What is −3⋅[1−204]-3 \cdot \begin{bmatrix} 1 & -2 \\ 0 & 4 \end{bmatrix}?

  1. [−3−204]\begin{bmatrix} -3 & -2 \\ 0 & 4 \end{bmatrix}
  2. [−360−12]\begin{bmatrix} -3 & 6 \\ 0 & -12 \end{bmatrix}
  3. [−3−60−12]\begin{bmatrix} -3 & -6 \\ 0 & -12 \end{bmatrix}
  4. [36012]\begin{bmatrix} 3 & 6 \\ 0 & 12 \end{bmatrix}

Which law says (c+d)A=cA+dA(c + d)A = cA + dA?

  1. Distributivity over scalar addition
  2. Commutativity of addition
  3. Associativity of scalar multiplication
  4. The zero law

Why is 0.5⋅R1+0.5⋅R20.5 \cdot R_1 + 0.5 \cdot R_2 a bad way to get a rotation halfway between rotations R1R_1 and R2R_2?

  1. It is undefined for 2×22 \times 2 matrices
  2. It is too slow
  3. It rotates by the sum of the angles
  4. The result is usually not a rotation; it shrinks vectors