← Back to Blog

Linear independence

math > linear-algebra

2025-10-073 min read

#linear-algebra #math #vectors

This blog is based on Jong-han Kim's Linear Algebra

Linear dependence

set of nn-vectors a1,,ak (with k1){a_1, \dots, a_k} \ (\text{with } k \geq 1) is linearly dependent if

β1a1++βkak=0\beta_1 a_1 + \dots + \beta_k a_k = 0

holds for some β1,,βk\beta_1, \dots, \beta_k that are not all zero


Linear independence

set of nn-vectors a1,,ak (with k1){a_1, \dots, a_k} \ (\text{with } k \geq 1) is linearly independent if

β1a1++βkak=0\beta_1 a_1 + \dots + \beta_k a_k = 0

holds only when β1==βk=0\beta_1 = \dots = \beta_k = 0

e.g., the unit nn-vectors e1,,ene_1, \dots, e_n are linearly independent

Linear combinations of linearly independent vectors

suppose xx is linear combination of linearly independent vectors a1,,aka_1, \dots, a_k

x=β1a1++βkakx = \beta_1 a_1 + \dots + \beta_k a_k

the coefficients β1,,βk\beta_1, \dots, \beta_k are unique, i.e. if

x=γ1a1++γkakx = \gamma_1a_1 + \dots + \gamma_ka_k

then βi=γi\beta_i = \gamma_i for i=1,,ki = 1, \dots, k

this means that (in principle) we can deduce the coefficients from xx
to see why, note that

(β1γ1)a1++(βkγk)ak=0(\beta_1 - \gamma_1)a_1 + \dots + (\beta_k - \gamma_k)a_k = 0

and so (by linear independence) β1γ1==βkγk=0\beta_1 - \gamma_1 = \dots = \beta_k - \gamma_k = 0

Independence-dimension inequality


Basis

a set of nn linearly independent nn-vectors a1,,ana_1, \dots, a_n is called a basis
any nn-vector bb can be expressed as a linear combination of them

b=β1a1++βnanb = \beta_1a_1 + \dots + \beta_n a_n

for some β1,,βn\beta_1, \dots, \beta_n

and these coefficients are unique
formula above is called expansion of bb in the a1,,ana_1, \dots, a_n basis

e.g., e1,,ene_1, \dots, e_n is a basis, expansion of bb is

b=b1e1++bnenb = b_1e_1 + \dots + b_ne_n

Orthonormal vectors

set of nn-vectors a1,,aka_1, \dots, a_k are (mutually) orthogonal if aiaja_i \bot a_j for iji \neq j
they are normalized if ai=1\Vert a_i\Vert = 1 for i=1,,ki = 1, \dots, k
they are orthonormal if both hold
can be expressed using inner products as

aiTaj={1i=j0ija^T_ia_j = \begin{cases} 1 & i = j \\ 0 & i \neq j \end{cases}

orthonormal sets of vectors are linearly independent
by independent-dimension inequality, must have knk \leq n
when k=n,a1,,ank = n, a_1, \dots, a_n are an orthonormal basis

Orthonormal expansion

if a1,,ana_1, \dots, a_n is an orthonormal basis, we have for any nn-vector xx

x=(a1Tx)a1++(anTx)anx = (a^T_1 x)a_1 + \dots + (a^T_nx)a_n

called orthonormal expansion of xx (in the orthonormal basis)
to verify formula, take inner product of both sides with aia_i

Gram-Schmidt (orthonormalization) algorithm

given n-vectors a1,,akfor i=1,,k1. Orthogonalization: q~i=ai(q1Tai)q1(qi1Tai)qi12. Test for linear dependence: if q~i=0, quit3. Normalization: qi=q~i/q~i\begin{align*} & \textbf{given } \textit{n}\text{-vectors } a_1, \dots, a_k \\ & \textbf{for } i = 1, \dots, k \\ & \quad \text{1. Orthogonalization: } \tilde{q}_i = a_i - (q_1^T a_i)q_1 - \cdots - (q_{i-1}^T a_i)q_{i-1} \\ & \quad \text{2. Test for linear dependence: if } \tilde{q}_i = 0, \text{ quit} \\ & \quad \text{3. Normalization: } q_i = \tilde{q}_i / \| \tilde{q}_i \| \end{align*}

if G-S does not stop early (in step 2), a1,,aka_1, \dots, a_k are linearly independent
if G-S stops early in iteration i=ji=j, then aja_j is a linear combination of a1,,aj1a_1, \dots, a_{j-1} (so a1,,aka_1, \dots, a_k are linearly dependent)

Code

import numpy as np

def gram_schmidt(vectors):
  A = np.array(vectors, dtype=float).T
  n, k = A.shape

  Q = np.zeros((n, k))

  for i in range(k):
    a_i = A[:, i]
    q_tilde = a_i

    for j in range(i):
      q_j = Q[:, j]
      projection = np.dot(q_j.T, a_i) * q_j
      q_tilde = q_tilde - projection

    norm_q_tilde = np.linalg.norm(q_tilde)

    if norm_q_tilde < 1e-10:
      print("linear dependent")
      return Q[:, :i]

    Q[:, i] = q_tilde / norm_q_tilde

  return Q

a1 = [1, 1, 0]
a2 = [2, 0, 1]
a3 = [0, 1, 2]
vectors_independent = [a1, a2, a3]

orthonormal_vectors = gram_schmidt(vectors_independent)
print(orthonormal_vectors.T)
print(np.dot(orthonormal_vectors.T, orthonormal_vectors))

print('='*30)

b1 = [1, 0, 1]
b2 = [0, 1, 1]
b3 = [2, 1, 3]
vectors_dependent = [b1, b2, b3]

orthonormal_vectors_dep = gram_schmidt(vectors_dependent)

print(orthonormal_vectors_dep.T)
[[ 0.70710678  0.70710678  0.        ]
 [ 0.57735027 -0.57735027  0.57735027]
 [-0.40824829  0.40824829  0.81649658]]
[[ 1.00000000e+00  2.50235355e-16  1.47380436e-17]
 [ 2.50235355e-16  1.00000000e+00 -3.33168241e-17]
 [ 1.47380436e-17 -3.33168241e-17  1.00000000e+00]]
==============================
linear dependent
[[ 0.70710678  0.          0.70710678]
 [-0.40824829  0.81649658  0.40824829]]