TExcelTAD
Home › Linear Algebra & Matrix Theory › Basis and Dimension

Basis and Dimension

A basis is a list of vectors from which every vector of the space can be built in exactly one way. The number of vectors in a basis, the dimension, is the same for every basis, and it is the true "size" of a space. Choosing a good basis is a design decision: the Bernstein basis of polynomials, for example, is what makes Bézier curves work.

Definitions

A list v1,…,vn\mathbf{v}_1, \ldots, \mathbf{v}_n in a vector space VV is a basis of VV if it is

  1. linearly independent, and
  2. spans VV (Linear Combinations, Span and Linear Independence).

Then every v∈V\mathbf{v} \in V has exactly one expression v=c1v1+⋯+cnvn\mathbf{v} = c_1\mathbf{v}_1 + \cdots + c_n\mathbf{v}_n. Spanning gives at least one; independence gives at most one, since two different expressions would subtract to a nontrivial combination equal to 0\mathbf{0}. The numbers (c1,…,cn)(c_1, \ldots, c_n) are the coordinates of v\mathbf{v} in this basis, written [v]B[\mathbf{v}]_B.

Theorem. If VV has a basis with nn vectors, every basis of VV has nn vectors. This nn is the dimension, dim⁡V\dim V. (The key step, as in the Rn\mathbb{R}^n lesson Basis and Dimension: in a space spanned by nn vectors, any n+1n + 1 vectors are dependent.)

Two shortcuts follow. In a space of dimension nn:

  • any nn independent vectors already span, so they are a basis;
  • any nn vectors that span are already independent, so they are a basis.

Dimensions of familiar spaces

Space Standard basis Dimension
Rn\mathbb{R}^n e1,…,en\mathbf{e}_1, \ldots, \mathbf{e}_n nn
PnP_n (degree ≤n\le n) 1,x,x2,…,xn1, x, x^2, \ldots, x^n n+1n + 1
Mm×nM_{m \times n} the matrices EijE_{ij} with a single 1 m⋅nm \cdot n
symmetric n×nn \times n matrices EiiE_{ii} and Eij+EjiE_{ij} + E_{ji} (i<ji < j) n(n+1)/2n(n + 1)/2
solutions of y′′+y=0y'' + y = 0 cos⁡x,sin⁡x\cos x, \sin x 2
GF(2)n\mathrm{GF}(2)^n e1,…,en\mathbf{e}_1, \ldots, \mathbf{e}_n nn (with 2n2^n vectors in total)
all polynomials PP 1,x,x2,…1, x, x^2, \ldots infinite
C[0,1]C[0, 1] no finite basis infinite

A space with no finite basis is infinite-dimensional. In such a space, there are arbitrarily long independent lists (1,x,…,xk1, x, \ldots, x^k for any kk).

Coordinates change with the basis

The coordinates of a vector depend on the basis. In P2P_2 with the basis 1,x,x21, x, x^2, the polynomial 3+2x+x23 + 2x + x^2 has coordinates (3,2,1)(3, 2, 1). In the basis 1,(x−1),(x−1)21, (x - 1), (x - 1)^2 it has coordinates (6,4,1)(6, 4, 1), since 3+2x+x2=6+4(x−1)+(x−1)23 + 2x + x^2 = 6 + 4(x - 1) + (x - 1)^2. Neither is more correct. A basis is a coordinate system, and you pick the one that makes the job easy.

The Bernstein basis and Bézier curves

For a fixed degree nn, the Bernstein polynomials are

Bi,n(t)=C(n,i)⋅ti⋅(1−t)n−i,i=0,1,…,n,C(n,i)=n!i!(n−i)!degree 3:B0=(1−t)3,B1=3t(1−t)2,B2=3t2(1−t),B3=t3\begin{aligned} &B_{i,n}(t) = C(n, i) \cdot t^i \cdot (1 - t)^{n-i}, \qquad i = 0, 1, \ldots, n, \qquad C(n, i) = \frac{n!}{i!(n - i)!} \\ &\text{degree 3:} \quad B_0 = (1 - t)^3, \quad B_1 = 3t(1 - t)^2, \quad B_2 = 3t^2(1 - t), \quad B_3 = t^3 \end{aligned}

There are n+1n + 1 of them in the (n+1)(n + 1)-dimensional space PnP_n, so they form a basis as soon as they are independent. Their coefficient columns in the basis 1,t,t2,t31, t, t^2, t^3 form a triangular matrix with nonzero diagonal:

python · try it yourself
from sympy import symbols, binomial, Poly, Matrix, expand

t = symbols("t")
n = 3
B = [binomial(n, i) * t**i * (1 - t)**(n - i) for i in range(n + 1)]
M = Matrix([[Poly(b, t).coeff_monomial(t**k) for b in B] for k in range(n + 1)])
print("columns = Bernstein polynomials in the basis 1, t, t^2, t^3:")
for row in M.tolist():
    print("  ", row)
print("det =", M.det(), "-> a basis of P3")
print("sum of the basis:", expand(sum(B)))
columns = Bernstein polynomials in the basis 1, t, t^2, t^3:
   [1, 0, 0, 0]
   [-3, 3, 0, 0]
   [3, -6, 3, 0]
   [-1, 3, -3, 1]
det = 9 -> a basis of P3
sum of the basis: 1

The determinant 9≠09 \ne 0 proves independence. The basis also adds up to 1 (because (t+(1−t))n=1(t + (1 - t))^n = 1), and every Bi,nB_{i,n} is ≥0\ge 0 on [0,1][0, 1]. These two facts are what graphics needs.

A Bézier curve with control points P0,…,PnP_0, \ldots, P_n is the curve whose Bernstein coordinates are those points:

B(t)=P0B0,n(t)+P1B1,n(t)+⋯+PnBn,n(t),0≤t≤1B(t) = P_0B_{0,n}(t) + P_1B_{1,n}(t) + \cdots + P_nB_{n,n}(t), \qquad 0 \le t \le 1

Since the weights are non-negative and add up to 1, every B(t)B(t) is a weighted average of the control points: the curve stays inside their convex hull, starts at P0P_0 (only B0B_0 is nonzero at t=0t = 0) and ends at PnP_n. Moving one control point changes one coordinate, which bends the curve smoothly (Bézier Curves).

python · try it yourself
import numpy as np
import matplotlib.pyplot as plt
from math import comb

P = np.array([[0.0, 0.0], [1.0, 2.0], [3.0, 3.0], [4.0, 0.0]])
n = len(P) - 1
ts = np.linspace(0, 1, 101)
weights = np.array([[comb(n, i) * t**i * (1 - t)**(n - i) for i in range(n + 1)] for t in ts])
curve = weights @ P                          # each row: Bernstein weights times control points

plt.figure(figsize=(6, 4))
plt.plot(P[:, 0], P[:, 1], "o--", color="0.6", label="control polygon")
plt.plot(curve[:, 0], curve[:, 1], lw=2, label="cubic Bézier")
plt.legend(); plt.gca().set_aspect("equal"); plt.grid(alpha=0.3)
print("B(0) =", curve[0].tolist(), " B(1) =", curve[-1].tolist(), " B(0.5) =", curve[50].tolist())
print("weights at t = 0.5:", weights[50].tolist())
B(0) = [0.0, 0.0]  B(1) = [4.0, 0.0]  B(0.5) = [2.0, 1.875]
weights at t = 0.5: [0.125, 0.375, 0.375, 0.125]

At t=0.5t = 0.5 the weights are 18,38,38,18\frac{1}{8}, \frac{3}{8}, \frac{3}{8}, \frac{1}{8}, so B(0.5)=(P0+3P1+3P2+P3)/8=(2,1.875)B(0.5) = (P_0 + 3P_1 + 3P_2 + P_3)/8 = (2, 1.875).

In software

  • Fonts and vector graphics: TrueType glyphs use quadratic Bézier curves, PostScript, CFF fonts and SVG paths use cubic ones; all are polynomials stored by their Bernstein coordinates.
  • Animation and CSS: cubic-bezier(x1, y1, x2, y2) easing curves are cubic Béziers with P0=(0,0)P_0 = (0, 0) and P3=(1,1)P_3 = (1, 1).
  • Compression and ML: storing a signal in a better basis (Fourier, wavelets, principal components) concentrates it in few coordinates (The Singular Value Decomposition).
  • Numerics: the monomial basis 1,x,x2,…1, x, x^2, \ldots is badly conditioned for high degree; numerical code prefers Chebyshev or Bernstein bases for the same space.

Exercises

Exercise 1: Upper triangular matrices

What is the dimension of the space of 2×22 \times 2 upper triangular matrices? Give a basis.

Answer

Dimension 3; basis E11=[1000]E_{11} = \begin{bmatrix} 1 & 0 \\ 0 & 0 \end{bmatrix}, E12=[0100]E_{12} = \begin{bmatrix} 0 & 1 \\ 0 & 0 \end{bmatrix}, E22=[0001]E_{22} = \begin{bmatrix} 0 & 0 \\ 0 & 1 \end{bmatrix}.

Solution

Every upper triangular matrix is [ab0d]=a⋅E11+b⋅E12+d⋅E22\begin{bmatrix} a & b \\ 0 & d \end{bmatrix} = a \cdot E_{11} + b \cdot E_{12} + d \cdot E_{22} (spanning), and this is the zero matrix only if a=b=d=0a = b = d = 0 (independent).

Exercise 2: Degree-1 Bernstein coordinates

Find the coordinates of p(t)=1+2tp(t) = 1 + 2t in the Bernstein basis B0=1−tB_0 = 1 - t, B1=tB_1 = t.

Answer

(1,3)(1, 3).

Solution
a(1−t)+b⋅t=a+(b−a)t=1+2t→a=1, b−a=2→b=3a(1 - t) + b \cdot t = a + (b - a)t = 1 + 2t \quad \to \quad a = 1, \ b - a = 2 \quad \to \quad b = 3

Shortcut: for degree 1 the coordinates are the values p(0)=1p(0) = 1 and p(1)=3p(1) = 3. That is why a straight segment is drawn from its two endpoints.

Exercise 3: tt and t2t^2 in Bernstein form

Using the degree-2 basis B0=(1−t)2B_0 = (1 - t)^2, B1=2t(1−t)B_1 = 2t(1 - t), B2=t2B_2 = t^2, find the coordinates of 11, tt and t2t^2.

Answer

1→(1,1,1)1 \to (1, 1, 1); t→(0,12,1)t \to (0, \frac{1}{2}, 1); t2→(0,0,1)t^2 \to (0, 0, 1).

Solution
1=B0+B1+B2(partition of unity)t=12⋅2t(1−t)+t2=t−t2+t2=t→(0,12,1)t2=B2→(0,0,1)\begin{aligned} 1 &= B_0 + B_1 + B_2 && \text{(partition of unity)} \\ t &= \tfrac{1}{2} \cdot 2t(1 - t) + t^2 = t - t^2 + t^2 = t && \to \quad (0, \tfrac{1}{2}, 1) \\ t^2 &= B_2 && \to \quad (0, 0, 1) \end{aligned}

Exercise 4: Convert in code

Find the degree-2 Bernstein coordinates of 1+t+t21 + t + t^2, by hand and with SymPy.

Answer

(1,32,3)(1, \frac{3}{2}, 3).

Solution

From Exercise 3, add the coordinates of 11, tt and t2t^2: (1,1,1)+(0,12,1)+(0,0,1)=(1,32,3)(1, 1, 1) + (0, \frac{1}{2}, 1) + (0, 0, 1) = (1, \frac{3}{2}, 3). Check: a=p(0)=1a = p(0) = 1 and c=p(1)=3c = p(1) = 3.

python · try it yourself
from sympy import symbols, solve, expand, Poly

t, a, b, c = symbols("t a b c")
p = 1 + t + t**2
combo = a * (1 - t)**2 + b * 2 * t * (1 - t) + c * t**2
eqs = Poly(expand(combo - p), t).all_coeffs()     # every coefficient must vanish
print(solve(eqs, [a, b, c]))
{a: 1, b: 3/2, c: 3}

Test yourself

What is the dimension of P4P_4, the polynomials of degree at most 4?

  1. 4
  2. 5
  3. 16
  4. Infinite

In a 3-dimensional space, three linearly independent vectors…

  1. might not span the space
  2. always form a basis
  3. must include the zero vector
  4. are always orthogonal

Why does a Bézier curve stay inside the convex hull of its control points?

  1. Because the Bernstein polynomials are orthogonal
  2. Because on [0,1][0, 1] the Bernstein weights are non-negative and add up to 1
  3. Because the curve is a straight line
  4. Because the control points are a basis