TExcelTAD
Home › Linear Algebra & Matrix Theory › Linear Combinations

Linear Combinations

A linear combination mixes vectors using the only two operations we have: scale each one, then add. Almost every question in linear algebra comes down to linear combinations: can this vector be built from those? In how many ways? And asking that question turns out to be the same as solving a system of linear equations.

The definition

Given vectors v1,v2,…,vk\mathbf{v}_1, \mathbf{v}_2, \ldots, \mathbf{v}_k in Rn\mathbb{R}^n and scalars c1,c2,…,ckc_1, c_2, \ldots, c_k, the vector

c1v1+c2v2+⋯+ckvkc_1\mathbf{v}_1 + c_2\mathbf{v}_2 + \cdots + c_k\mathbf{v}_k

is a linear combination of v1,…,vk\mathbf{v}_1, \ldots, \mathbf{v}_k with coefficients (or weights) c1,…,ckc_1, \ldots, c_k. Example:

2⋅(1,0,3)−1⋅(0,1,1)+4⋅(1,1,0)=(2,0,6)+(0,−1,−1)+(4,4,0)=(6,3,5)2 \cdot (1, 0, 3) - 1 \cdot (0, 1, 1) + 4 \cdot (1, 1, 0) = (2, 0, 6) + (0, -1, -1) + (4, 4, 0) = (6, 3, 5)

Building every vector from the standard basis

The standard basis vectors of R3\mathbb{R}^3 are e1=(1,0,0)\mathbf{e}_1 = (1, 0, 0), e2=(0,1,0)\mathbf{e}_2 = (0, 1, 0) and e3=(0,0,1)\mathbf{e}_3 = (0, 0, 1). Every vector is a linear combination of them, with its own components as coefficients:

(x,y,z)=x⋅e1+y⋅e2+z⋅e3(x, y, z) = x \cdot \mathbf{e}_1 + y \cdot \mathbf{e}_2 + z \cdot \mathbf{e}_3

The same holds in Rn\mathbb{R}^n with e1,…,en\mathbf{e}_1, \ldots, \mathbf{e}_n. Other sets of vectors may or may not be able to build everything; that is the topic of Spans.

Is b a linear combination? Solve a system

Is b=(4,2,9)\mathbf{b} = (4, 2, 9) a linear combination of v1=(1,0,3)\mathbf{v}_1 = (1, 0, 3), v2=(2,1,1)\mathbf{v}_2 = (2, 1, 1) and v3=(0,1,2)\mathbf{v}_3 = (0, 1, 2)? We need c1,c2,c3c_1, c_2, c_3 with c1v1+c2v2+c3v3=bc_1\mathbf{v}_1 + c_2\mathbf{v}_2 + c_3\mathbf{v}_3 = \mathbf{b}. Comparing components gives one equation per component:

1⋅c1+2⋅c2+0⋅c3=40⋅c1+1⋅c2+1⋅c3=23⋅c1+1⋅c2+2⋅c3=9\begin{aligned} 1 \cdot c_1 + 2 \cdot c_2 + 0 \cdot c_3 &= 4 \\ 0 \cdot c_1 + 1 \cdot c_2 + 1 \cdot c_3 &= 2 \\ 3 \cdot c_1 + 1 \cdot c_2 + 2 \cdot c_3 &= 9 \end{aligned}

The columns of the coefficient matrix are exactly v1,v2,v3\mathbf{v}_1, \mathbf{v}_2, \mathbf{v}_3, and the right-hand side is b\mathbf{b}. So:

b\mathbf{b} is a linear combination of v1,…,vk\mathbf{v}_1, \ldots, \mathbf{v}_k   ⟺  \iff the system with augmented matrix [v1 v2 ⋯ vk∣b][\mathbf{v}_1\ \mathbf{v}_2\ \cdots\ \mathbf{v}_k \mid \mathbf{b}] is consistent.

python · try it yourself
from sympy import Matrix

v1, v2, v3 = Matrix([1, 0, 3]), Matrix([2, 1, 1]), Matrix([0, 1, 2])
b = Matrix([4, 2, 9])

A = Matrix.hstack(v1, v2, v3)      # vectors as columns
c = A.solve(b)
print("coefficients:", list(c))
print("check:", list(c[0] * v1 + c[1] * v2 + c[2] * v3))
coefficients: [2, 1, 1]
check: [4, 2, 9]

So b=2v1+v2+v3\mathbf{b} = 2\mathbf{v}_1 + \mathbf{v}_2 + \mathbf{v}_3. When the system is inconsistent, b\mathbf{b} is not a combination; when it has infinitely many solutions, b\mathbf{b} can be built in infinitely many ways.

python · try it yourself
from sympy import Matrix, symbols, linsolve

c1, c2 = symbols("c1 c2")
u1, u2 = Matrix([1, 2, 0]), Matrix([0, 1, 1])
for b in [Matrix([2, 7, 3]), Matrix([1, 1, 1])]:
    aug = Matrix.hstack(u1, u2, b)
    print(list(b), "->", linsolve(aug, [c1, c2]))
[2, 7, 3] -> {(2, 3)}
[1, 1, 1] -> EmptySet

(2,7,3)=2u1+3u2(2, 7, 3) = 2\mathbf{u}_1 + 3\mathbf{u}_2, but (1,1,1)(1, 1, 1) cannot be built from u1\mathbf{u}_1 and u2\mathbf{u}_2: the two vectors only reach a plane through the origin in R3\mathbb{R}^3.

AxA\mathbf{x} is a linear combination of the columns of A

This observation is worth remembering forever. For a matrix AA with columns a1,…,an\mathbf{a}_1, \ldots, \mathbf{a}_n and a vector x=(x1,…,xn)\mathbf{x} = (x_1, \ldots, x_n):

Ax=x1⋅a1+x2⋅a2+⋯+xn⋅anA\mathbf{x} = x_1 \cdot \mathbf{a}_1 + x_2 \cdot \mathbf{a}_2 + \cdots + x_n \cdot \mathbf{a}_n
python · try it yourself
import numpy as np

A = np.array([[1, 2, 0], [0, 1, 1], [3, 1, 2]])
x = np.array([2, 1, 1])
print("A @ x            :", A @ x)
print("sum of x_j * col_j:", sum(x[j] * A[:, j] for j in range(3)))
A @ x            : [4 2 9]
sum of x_j * col_j: [4 2 9]

So "solve Ax=bA\mathbf{x} = \mathbf{b}" and "write b\mathbf{b} as a combination of AA's columns" are the same problem, seen from two sides. You will use this view again and again, e.g. in Column Space, Row Space and Null Space.

In software

  • Colour mixing: every screen colour is a combination r⋅red+g⋅green+b⋅bluer \cdot \text{red} + g \cdot \text{green} + b \cdot \text{blue} of three primary vectors. Converting RGB to another colour space (YUV for video) changes which three vectors you combine.
  • Graphics: barycentric coordinates write a point inside a triangle as α⋅A+β⋅B+γ⋅C\alpha \cdot A + \beta \cdot B + \gamma \cdot C with α+β+γ=1\alpha + \beta + \gamma = 1; GPUs use them to blend vertex colours and texture coordinates. Bézier curves are combinations of control points.
  • ML: a linear model's prediction w1x1+⋯+wnxnw_1x_1 + \cdots + w_nx_n is a linear combination of features; an attention layer outputs a weighted combination of value vectors (Attention as Matrix Products).
  • Diet and blending problems: which mix of foods (each a vector of nutrients) meets a target vector of nutrients?

Exercises

Exercise 1: Compute a combination

Compute 3⋅(1,−1)−2⋅(2,0)+(0,5)3 \cdot (1, -1) - 2 \cdot (2, 0) + (0, 5).

Answer

(−1,2)(-1, 2).

Solution
(3,−3)−(4,0)+(0,5)=(3−4+0,−3−0+5)=(−1,2)(3, -3) - (4, 0) + (0, 5) = (3 - 4 + 0, -3 - 0 + 5) = (-1, 2)

Exercise 2: Find the coefficients

Write (7,4)(7, 4) as a combination of (1,2)(1, 2) and (3,−1)(3, -1).

Answer

(7,4)=(197)⋅(1,2)+(107)⋅(3,−1)(7, 4) = \left(\frac{19}{7}\right) \cdot (1, 2) + \left(\frac{10}{7}\right) \cdot (3, -1).

Solution
c1+3c2=72c1−c2=4→c2=2c1−4c1+6c1−12=7→c1=197,c2=387−287=107Check: 197+307=497=7 ✓387−107=287=4 ✓\begin{aligned} c_1 + 3c_2 &= 7 \\ 2c_1 - c_2 &= 4 && \to c_2 = 2c_1 - 4 \\ c_1 + 6c_1 - 12 &= 7 && \to c_1 = \tfrac{19}{7}, \quad c_2 = \tfrac{38}{7} - \tfrac{28}{7} = \tfrac{10}{7} \\ &\text{Check: } \tfrac{19}{7} + \tfrac{30}{7} = \tfrac{49}{7} = 7 \ \checkmark \qquad \tfrac{38}{7} - \tfrac{10}{7} = \tfrac{28}{7} = 4 \ \checkmark \end{aligned}

Exercise 3: Not reachable

Show that (1,0,0)(1, 0, 0) is not a linear combination of (1,1,0)(1, 1, 0) and (0,1,1)(0, 1, 1).

Answer

The system is inconsistent.

Solution
c1⋅(1,1,0)+c2⋅(0,1,1)=(c1,c1+c2,c2)=(1,0,0)→c1=1, c2=0, but then c1+c2=1≠0. Contradiction.\begin{aligned} &c_1 \cdot (1, 1, 0) + c_2 \cdot (0, 1, 1) = (c_1, c_1 + c_2, c_2) = (1, 0, 0) \\ &\to c_1 = 1,\ c_2 = 0, \text{ but then } c_1 + c_2 = 1 \ne 0. \text{ Contradiction.} \end{aligned}

Exercise 4: Paint mixing (code)

Three paints contain (red, yellow, blue) pigment fractions (0.6,0.3,0.1)(0.6, 0.3, 0.1), (0.1,0.7,0.2)(0.1, 0.7, 0.2) and (0.2,0.2,0.6)(0.2, 0.2, 0.6). How many litres of each make a mix with (2.0,3.2,2.3)(2.0, 3.2, 2.3) litres of pigment? Use SymPy with exact fractions.

Answer

2 L of paint 1, 3 L of paint 2 and 2.5 L of paint 3.

Solution

Put the paints as columns and solve. Rational("0.6") keeps 0.6 exact.

python · try it yourself
from sympy import Matrix, Rational as R

p1 = Matrix([R("0.6"), R("0.3"), R("0.1")])
p2 = Matrix([R("0.1"), R("0.7"), R("0.2")])
p3 = Matrix([R("0.2"), R("0.2"), R("0.6")])
target = Matrix([R("2.0"), R("3.2"), R("2.3")])
print(list(Matrix.hstack(p1, p2, p3).solve(target)))
[2, 3, 5/2]

Test yourself

b\mathbf{b} is a linear combination of v1,v2,v3\mathbf{v}_1, \mathbf{v}_2, \mathbf{v}_3 exactly when…

  1. b\mathbf{b} is shorter than all three
  2. b\mathbf{b} is perpendicular to v1\mathbf{v}_1
  3. v1,v2,v3\mathbf{v}_1, \mathbf{v}_2, \mathbf{v}_3 are parallel
  4. the system with columns v1,v2,v3\mathbf{v}_1, \mathbf{v}_2, \mathbf{v}_3 and right-hand side b\mathbf{b} is consistent

If AA has columns a1=(1,0)\mathbf{a}_1 = (1, 0) and a2=(2,3)\mathbf{a}_2 = (2, 3), what is A⋅(4,−1)A \cdot (4, -1)?

  1. (4,−3)(4, -3)
  2. (2,−3)(2, -3)
  3. (6,3)(6, 3)
  4. (2,3)(2, 3)

What are the coefficients of (5,−2,7)(5, -2, 7) in the standard basis e1,e2,e3\mathbf{e}_1, \mathbf{e}_2, \mathbf{e}_3?

  1. 1, 1, 1
  2. 5, -2, 7
  3. 7, -2, 5
  4. They do not exist