Essence of Linear Algebra (2): Linear Combinations and Vector Spaces
Chen Kai BOSS

Imagine you have a box with only red, green, and blue colored pencils. How many colors can you draw? The answer is: infinitely many. By mixing different proportions of RGB, from deep purple to light yellow, any color can be created. This is the power of linear combinations— building infinite possibilities from finite "ingredients." This chapter will reveal this magical mathematical mechanism and how it supports the entire edifice of linear algebra.

Starting from Mixing Colors: What Is a Linear Combination?

In Chapter 1, we understood that vectors are quantities with direction and magnitude. Now, let's think about a more interesting question: If you're given several vectors, which positions in space can you "reach" using them?

Linear Combinations in Daily Life

Before answering this abstract question, let's look at some familiar scenarios:

Scenario 1: Mixing Cocktails

Suppose you're a bartender with two base liquors: - Liquor A: 40% alcohol, 10g sugar per liter - Liquor B: 20% alcohol, 30g sugar per liter

You want to make a cocktail with 30% alcohol and 20g sugar. How do you do it?

If you use liters of A andliters of B, then: - Alcohol: - Sugar:Solving this system gives— half a liter of A plus half a liter of B.

Here,is a linear combination of vectorsand, with coefficientsand.

Scenario 2: Walking Navigation

You're standing at an intersection, and your friend tells you: "Walk 300 meters east, then 400 meters north."

In vector terms: -: Unit vector pointing east -: Unit vector pointing north

Your displacement is:This is also a linear combination! The coefficients are 300 and 400.

Scenario 3: RGB Colors

Every pixel on a computer monitor is a mixture of red (R), green (G), and blue (B) light:Where. For example: -= Pure red -= Yellow (red + green) -= Purple

Every color is a linear combination of the three "basis vectors" red, green, and blue.

Mathematical Definition of Linear Combinations

Now we can give a rigorous definition:

Definition (Linear Combination): Given vectorsand scalars, their linear combination is: Hereare called coefficients or weights.

Key Understanding: - Linear combinations only involve two operations: scalar multiplication and vector addition - The coefficientscan be any real numbers (positive, negative, or zero) - "Linear" means no squares, cubes, products, or other nonlinear terms

Why Is It Called "Linear"?

Consider a vectorin the 2D plane.

What do all its scalar multiplesform?

Whengoes fromto: -: The origin -: -: -:All these points together form a line passing through the origin!

This is the geometric origin of "linear": scalar multiples of a single vector form a line.

Linear Combinations in 2D Space

Now consider two non-parallel vectorsand.

Where can their linear combinationreach?

Whenrange over all real numbers,covers the entire 2D plane!

Let's verify a few points: - - -

Conclusion: Linear combinations of two non-parallel vectors can cover the entire 2D plane.

But what if two vectors are parallel? For example,and?

Note that, so their linear combination:No matter howare chosen, the result is always a scalar multiple of— they can only cover a line!

This leads to a key question: Given a set of vectors, what are all the positions they can "reach"?

Span: All Places Vectors Can Reach

Definition of Span

Definition (Span): The span of a vector setis the set of all possible linear combinations:

Intuition: - Span is all the positions you can "reach" using these vectors - Imagine you have a "vector remote control" that can adjust each vector's coefficient - All the positions you can reach by adjusting the coefficients constitute the span

Different Cases of Span

Let's systematically look at the spans of different vector combinations:

Case 1: A Single Non-Zero Vector: A line through the origin (in the direction of)

For example:This is the line through the origin with slope 2.

Case 2: Two Collinear Vectors (Parallel)where: Still just a line

Even though there are two vectors, the second doesn't provide a new "direction," so the span doesn't grow.

Case 3: Two Non-Collinear 2D Vectorswhereare not parallel: The entireplane

For example: Case 4: Two 3D Vectorsin: A plane through the origin

For example:is the-plane (all points where)

Case 5: Three Coplanar 3D Vectors

Still just a plane. The third vector, if it can be expressed using the first two, doesn't increase the span.

Case 6: Three Non-Coplanar 3D Vectors: The entire 3D space

Important Observations: The Shape of Span

From the examples above, we can see: - Span always passes through the origin (because when all coefficients are 0, we get the zero vector) - Span is closed (the linear combination of two points in the span is still in the span) - The "size" of the span depends on the "degree of independence" between vectors

These properties make span a special geometric object — a subspace (detailed later).

Practical Significance of Span

Example 1: Can You Mix the Target from Available Materials?

A chemistry lab has three solutions: - Solution A: 5% acid, 10% salt - Solution B: 10% acid, 5% salt - Solution C: 2% acid, 2% salt

Question: Can you mix a solution with 15% acid and 12% salt?

View each solution as a vector:The question becomes: Isin?

Note thatare not parallel, so.

Thereforemust be in the span — it can be mixed!

Example 2: Coordinate Systems in Graphics

In 3D games, each object has its own local coordinate system defined by three vectors.

Any point on the object's surface can be expressed as a linear combination of these three vectors.

If, it means this local coordinate system is "complete" and can describe any position in 3D space.

Linear Independence: A Vector Set Without Redundancy

From the previous discussion, we noticed a phenomenon: sometimes adding a vector doesn't increase the span — for example, when the new vector can be "expressed" by existing vectors.

This leads to one of the most important concepts in linear algebra: linear independence.

Starting from Redundancy

Consider three vectors: - - -What is the span of these three vectors?

Note that, so:So is redundant— removing it doesn't affect the span.

Definition of Linear Independence

Definition (Linear Independence): A vector setis linearly independent if and only if: > holds only when.

Equivalently: If there exist non-zero coefficients that make the linear combination equal to the zero vector, the vectors are linearly dependent.

Intuitive Understanding: - Linearly independent = no vector is "redundant" - Linearly independent = each vector provides a new "direction" - Linearly independent = you can't "construct" any one vector from the others

Geometric Understanding

2D case: - Two vectors are linearly independentThey are not parallel - Two vectors are linearly dependentThey are collinear

3D case: - Three vectors are linearly independentThey are not coplanar - Three vectors are linearly dependentThey are coplanar

Methods for Determining Linear Independence

Method 1: Definition Method

Setand solve this homogeneous system. - If only the zero solutionexists: Linearly independent - If non-zero solutions exist: Linearly dependent

Example: Determine ifare linearly independent.

SetWe get the system: Solving:(verify:)

A non-zero solution exists, so these three vectors are linearly dependent!

In fact,and, so.

Method 2: Determinant Method (Only forvectors indimensions)

Form a matrix with the-dimensional vectors as columns (or rows) and compute the determinant: - Determinant: Linearly independent - Determinant: Linearly dependent

For the example above:So they are linearly dependent. (Determinant computation will be detailed in Chapter 4)

Important Properties of Linear Independence

Property 1: Ifis linearly independent, then any of its subsets is also linearly independent.

Conversely: If some subset is linearly dependent, then the whole set is linearly dependent.

Property 2: In, more thanvectors must be linearly dependent.

Intuition:-dimensional space has at most"independent directions."

Property 3: Ifis linearly independent and, then the representation ofis unique.

This property is extremely important — it guarantees the uniqueness of coordinates.

Equivalent Conditions for Linear Dependence

The following conditions are equivalent (choose any one to judge):

1.is linearly dependent 2. There exist non-zerosuch that$c_i_i = n$-dimensional vectors) The determinant of the formed matrix is 0

Basis: The Smallest Complete Set

Now we can define one of the most central concepts in linear algebra: the basis.

Definition of Basis

Definition (Basis): A basis of a vector spaceis a vector setsatisfying: 1. Linearly independent: No redundancy 2. Spans: Intuition: - A basis is the "smallest complete toolbox" - "Complete" means it can represent any vector in the space - "Smallest" means no extra vectors

Standard Basis

The standard basis ofconsists ofvectors:Eachhas 1 in the-th position and 0 elsewhere.

For example, the standard basis of:Characteristics of the standard basis: - Mutually perpendicular (orthogonal) - All have length 1 (unit vectors) - Coordinatesare the coefficients in the standard basis:

Non-Standard Bases

Bases are not unique! The following vector sets are all bases for:

Example 1:Verification: - Linearly independent? Set, get, so. - Spans? Two non-parallel 2D vectors span all of.

Example 2:This is a "stretched version" of the standard basis — stretched by 2 along the-axis and by 3 along the-axis.

Example 3:This is a "slanted" basis but still valid.

Coordinates: Same Vector in Different Bases

What are the coordinates of vectorin different bases?

In the standard basis:, coordinates are In basis: SetGet, solving givesCoordinates are Key Understanding: - The same vector (the same arrow in space) has different coordinates in different bases - Coordinates only have meaning after specifying a basis - Thewe usually write implicitly uses the standard basis

Existence and Uniqueness of Bases

Existence Theorem: Every non-zero vector space has a basis.

Uniqueness: Bases are not unique, but the number of vectors in any basis is unique (this is the dimension).

How to find a basis?

Method: Start by selecting vectors from the space, adding them one by one, checking if they're still linearly independent each time. When you can't add any more (any new vector would cause linear dependence), you've found a basis.

Dimension: The "Degrees of Freedom" of a Space

Definition of Dimension

Definition (Dimension): The dimension of a vector spaceis the number of vectors in any basis of. Written as.

Why is this definition valid? An important theorem guarantees: all bases of the same vector space have the same number of vectors.

Intuition of Dimension

Dimension can be understood as: - How many independent parameters are needed to describe a point in the space - How many independent directions of movement exist in the space - The maximum number of linearly independent vectors the space can hold

Dimensions of Common Spaces

Space Dimension Explanation
A point (zero vector space) 0 No freedom of movement
A line 1 Can only move back and forth
A plane 2 Back-forth + left-right
3D space 3 Back-forth + left-right + up-down
independent directions

Relationship Between Dimension and Linear Independence

Key Theorem: In an-dimensional space: - More thanvectors must be linearly dependent - Exactlylinearly independent vectors form a basis - Fewer thanvectors cannot span the entire space

Example: In: - 4 vectors must be linearly dependent (may spanbut with redundancy) - 3 linearly independent vectors form a basis - 2 vectors can span at most a plane

Subspaces: Spaces Within Spaces

Definition of Subspace

Definition (Subspace): A subspace of a vector spaceis a subsetofsatisfying: 1. Contains the zero vector:> 2. Closed under addition: If, then> 3. Closed under scalar multiplication: If, thenfor any scalar Intuition: A subspace is a "space within a space"— it is itself a vector space but "lives" inside a larger space.

Examples of Subspaces

Subspaces of:

  1. Zero space: Contains only the zero vector, dimension 0
  2. A line through the origin: e.g.,, dimension 1
  3. A plane through the origin: e.g., (the-plane), dimension 2
  4. itself: Dimension 3

Note: Lines or planes not passing through the origin are not subspaces!

For example, (the plane) is not a subspace because: - It doesn't contain the zero vector -, where, not closed

Span as Subspace

Important Fact: The span of any set of vectors is a subspace.satisfies: 1. 2. Sum of two linear combinations is still a linear combination 3. Linear combination times a scalar is still a linear combinationThis gives us a simple way to construct subspaces: take some vectors and find their span.

Intersection and Sum of Subspaces

Intersection: The intersection of two subspaces is still a subspace.

Example: The intersection of the-plane and-plane inis the-axis.

Sum:Example: The sum of the-axis and-axis is the-plane.

Dimension Formula:

Practical Case Study: RGB Color Space

Let's dive deep into the RGB color space as a practical application.

Mathematical Structure of the RGB Model

In the RGB color model: - Each color is represented as a 3D vector -(8-bit color depth) or(normalized)

The three basic color vectors:Any color is a linear combination of these:

Linearity of Color Mixing

Additive mixing (mixing of light, as in monitors):Example: Redplus greenequals yellow Brightness adjustment: darkens,brightens.

Color Space as a Vector Space

Strictly speaking, if we restrict, the RGB color space is not a vector space (not closed under addition and scalar multiplication).

But if we allow(a theoretical extension), we get thevector space.

Practical application: In image processing, intermediate calculations often use floating-point numbers (unrestricted range), and the values are clipped toonly at the end.

Subspaces of Color Space

Grayscale images: Colors where This is a 1-dimensional subspace of (a line through the origin).

Colors seen by certain types of color-blind people:

Some types of color blindness can only distinguish blue and yellow (red+green), which is equivalent to projectingonto a 2-dimensional subspace.

Color Space Transformations

Different color spaces (RGB, HSV, LAB, etc.) correspond to different basis choices.

Converting from RGB to another color space is a change of basis— this involves matrix multiplication (topic of the next chapter).

Python Implementation

Let's verify this chapter's concepts with code.

Checking Linear Independence

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import numpy as np

def is_linearly_independent(vectors):
"""
Check if a set of vectors is linearly independent
vectors: list of vectors, each vector is a numpy array
"""
if len(vectors) == 0:
return True

# Stack vectors as columns of a matrix
matrix = np.column_stack(vectors)

# Compute rank
rank = np.linalg.matrix_rank(matrix)

# If rank equals number of vectors, linearly independent
return rank == len(vectors)

# Test
v1 = np.array([1, 2, 3])
v2 = np.array([4, 5, 6])
v3 = np.array([7, 8, 9])

print(f"v1, v2, v3 linearly independent: {is_linearly_independent([v1, v2, v3])}") # False

v4 = np.array([1, 0, 0])
v5 = np.array([0, 1, 0])
v6 = np.array([0, 0, 1])

print(f"v4, v5, v6 linearly independent: {is_linearly_independent([v4, v5, v6])}") # True

Checking if a Vector Is in Span

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
def is_in_span(target, basis_vectors):
"""
Check if target vector is in the span of basis_vectors
"""
matrix = np.column_stack(basis_vectors)

# Try to solve the linear system matrix @ coeffs = target
try:
coeffs, residuals, rank, s = np.linalg.lstsq(matrix, target, rcond=None)
# Check if it's actually a solution (small residual)
reconstructed = matrix @ coeffs
return np.allclose(reconstructed, target)
except:
return False

# Test
v1 = np.array([1, 0])
v2 = np.array([0, 1])
target = np.array([3, 5])

print(f"(3,5) in span(v1, v2): {is_in_span(target, [v1, v2])}") # True

v3 = np.array([1, 1])
v4 = np.array([2, 2]) # Collinear with v3
target2 = np.array([1, 0])

print(f"(1,0) in span(v3, v4): {is_in_span(target2, [v3, v4])}") # False

Visualizing Span

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import matplotlib.pyplot as plt

def visualize_span_2d(v1, v2, num_points=50):
"""Visualize the span of two 2D vectors"""
fig, ax = plt.subplots(figsize=(8, 8))

# Generate grid
c1 = np.linspace(-2, 2, num_points)
c2 = np.linspace(-2, 2, num_points)

for i in c1:
for j in c2:
point = i * v1 + j * v2
ax.plot(point[0], point[1], 'b.', alpha=0.3, markersize=2)

# Draw original vectors
ax.quiver(0, 0, v1[0], v1[1], angles='xy', scale_units='xy', scale=1, color='r', width=0.02)
ax.quiver(0, 0, v2[0], v2[1], angles='xy', scale_units='xy', scale=1, color='g', width=0.02)

ax.set_xlim(-5, 5)
ax.set_ylim(-5, 5)
ax.set_aspect('equal')
ax.grid(True)
ax.set_title('Span of two vectors')
plt.show()

# Example
v1 = np.array([1, 0.5])
v2 = np.array([0.3, 1])
visualize_span_2d(v1, v2)

Common Misconceptions and Clarifications

Misconception 1: "Vectorsandcan span the 2D plane"

Wrong!, they are collinear and can only span a line.

Misconception 2: "Three vectors always span a larger space than two vectors"

Not necessarily! If the third vector is in the span of the first two, the space doesn't grow.

Misconception 3: "Linearly independent vectors must be orthogonal (perpendicular)"

Wrong!andare linearly independent but not orthogonal. Orthogonality is a stronger condition than linear independence.

Misconception 4: "The basis is unique"

Wrong! The same space can have infinitely many bases. But the dimension (size of the basis) is unique.

Misconception 5: "A subspace can be any subset"

Wrong! A subspace must satisfy three conditions (contains zero, closed under addition, closed under scalar multiplication).

Exercises

Basic Problems

1. Determine if the following vector sets are linearly independent:

(a) (b) (c) (d) 2. Find the dimension of the span of the following vector sets:

(a)in (b)in (c)in 3. Canbe expressed as a linear combination ofand? If so, find the coefficients.

4. What is the dimension of? How many vectors are needed to form a basis?

5. Determine if the following sets are subspaces of:

(a) (b) (c) (d)

Intermediate Problems

6. Prove: Ifis linearly independent, thenis also linearly independent.

7. Given, find asuch thatis a basis for.

8. Prove: Anyvectors inmust be linearly dependent.

9. Let,. Findand.

10. Prove: Ifis linearly independent and, thencan be uniquely expressed as a linear combination of the.

Thinking Problems

11. The RGB color space is 3-dimensional. Can all colors be represented using mixtures of only 2 colors? Why or why not?

12. Consider the set of allreal matrices with matrix addition and scalar multiplication. Is this a vector space? If so, what is its dimension? Give a basis.

13. Why is a line through the origin a subspace, while a line not through the origin is not? Analyze using the three conditions in the definition.

14. In, 100 random vectors are almost always linearly independent, but 101 vectors must be linearly dependent. Why?

Programming Problems

15. Write a Python function to check if a given set of vectors is linearly independent. Use the determinant or rank method.

16. Implement a function that, given a set of vectors, finds a maximal linearly independent subset (i.e., a basis for the span).

17. Write a program to visualize the plane spanned by two vectors in 3D space.

18. Implement an interactive program: the user inputs two 2D vectors and coefficients, and the program displays the linear combination result and visualizes "moving within the span."


Exercise Solutions

Basic Problems

1. Determine if the following vector sets are linearly independent:

(a)

Solution: Linearly dependent. Note that, so they are collinear.

(b)

Solution: Linearly independent. These are the standard basis vectors, which are clearly independent.

(c)

Solution: Linearly independent. Set up: Solving:. Only the zero solution exists, so they're independent.

(d)

Solution: Linearly dependent. Note that (verify:).

2. Find the dimension of the span:

(a)in: Dimension 1 (a line)

(b)in: Dimension 1 (collinear vectors span a line)

(c)in: Dimension 2 (two non-collinear vectors span a plane)

3. Canbe expressed as a linear combination ofand?

Solution: Set up: From the second equation:. Substituting into the first:

Answer: Yes,

4. Dimension of: 5. A basis needs 5 linearly independent vectors.

5. Determine if the following are subspaces of:

(a)

Solution: Yes, this is a subspace. - Contains zero:satisfies - Closed under addition: Ifand, then - Closed under scalar multiplication: If, then

(b)

Solution: No, not a subspace. - Doesn't contain zero:gives

(c)

Solution: No, not a subspace. - Not closed under addition:andare in the set (both satisfy), but their sumgives

Intermediate Problems

6. Find all possible dimensions of subspaces of:

Solution: 0, 1, 2, 3, 4 - 0: The zero space - 1: Lines through the origin - 2: Planes through the origin - 3: 3D hyperplanes through the origin - 4:itself

7. Prove: Ifis linearly independent, thenis also linearly independent.

Proof: Supposewere linearly dependent. Then there exist non-zero coefficients (not both zero) such that:But then:This is a non-trivial linear combination ofequaling zero, contradicting their linear independence. Therefore,must be linearly independent. ∎

8. Find a basis forwhere: - - -

Solution: Check ifcan be written as a combination of: This gives: From the first two:. Check in the third: Since, it's redundant.

Answer:or equivalentlyforms a basis. The span is a 2D plane in.

9. Given basisof, find the coordinates ofwith respect to.

Solution: Set up: Adding:. Then.

Answer:

10. Is the set of allupper triangular matrices a subspace of allmatrices?

Solution: Yes.

Upper triangular matrices have the form.

  • Contains zero matrix:
  • Closed under addition: Sum of two upper triangular matrices is upper triangular
  • Closed under scalar multiplication: Scalar times upper triangular is upper triangular

11. Prove or disprove: The set of all invertiblematrices is a subspace of allmatrices.

Solution: False (not a subspace).

Counterexample: The identity matrixis invertible, butis also invertible. However, (the zero matrix), which is not invertible.

Therefore, the set is not closed under addition, so it's not a subspace.

12. Given vectors in:. Are they linearly independent? Do they form a basis for?

Solution: Check the determinant:

Answer: Since the determinant is non-zero, they are linearly independent. Since we have 3 linearly independent vectors in (a 3-dimensional space), they form a basis for.

Advanced Problems

13. Why is a line through the origin a subspace, while a line not through the origin is not?

Solution:

Line through originfor some: - Contains zero: When, we get - Closed under addition: - Closed under scalar multiplication:

Line not through originwhere: - Doesn't contain zero: Settinggives - Not closed under addition:, which has a "" term, not in the original form

14. In, 100 random vectors are almost always linearly independent, but 101 vectors must be linearly dependent. Why?

Solution:

Dimension theorem: In an-dimensional space, any set of more thanvectors must be linearly dependent.

For: - Maximum number of linearly independent vectors = dimension = 100 - 100 "generic" vectors (in general position) will be linearly independent with probability 1 - 101 vectors must be linearly dependent, because you can't have more than 100 independent directions in a 100-dimensional space

Intuition: Think of it as degrees of freedom. You have only 100 "slots" for independent directions. The 101st vector must be expressible as a combination of the first 100.

Programming Problems

15. Python function to check linear independence:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import numpy as np

def is_linearly_independent(vectors):
"""
Check if vectors are linearly independent
"""
if len(vectors) == 0:
return True

A = np.column_stack(vectors)
rank = np.linalg.matrix_rank(A)

return rank == len(vectors)

# Test
v1 = np.array([1, 2, 3])
v2 = np.array([4, 5, 6])
v3 = np.array([7, 8, 9])

print(f"Independent: {is_linearly_independent([v1, v2, v3])}") # False

16. Find maximal linearly independent subset:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
def maximal_independent_subset(vectors):
"""
Find maximal linearly independent subset (a basis for the span)
"""
A = np.column_stack(vectors)
m, n = A.shape

independent_indices = []
current_matrix = np.zeros((m, 0))

for i in range(n):
test_matrix = np.column_stack([current_matrix, A[:, i]])

if np.linalg.matrix_rank(test_matrix) > len(independent_indices):
independent_indices.append(i)
current_matrix = test_matrix

basis = [vectors[i] for i in independent_indices]
return independent_indices, basis

# Test
vectors = [
np.array([1, 0, 0]),
np.array([1, 1, 0]),
np.array([2, 1, 0]), # Dependent on first two
np.array([0, 0, 1])
]

indices, basis = maximal_independent_subset(vectors)
print(f"Basis indices: {indices}") # [0, 1, 3]

17. Visualize plane spanned by two vectors in 3D:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

def visualize_span_3d(v1, v2):
"""Visualize plane spanned by two 3D vectors"""
fig = plt.figure(figsize=(10, 8))
ax = fig.add_subplot(111, projection='3d')

# Generate points on the plane
s = np.linspace(-2, 2, 20)
t = np.linspace(-2, 2, 20)
S, T = np.meshgrid(s, t)

X = S * v1[0] + T * v2[0]
Y = S * v1[1] + T * v2[1]
Z = S * v1[2] + T * v2[2]

# Plot plane
ax.plot_surface(X, Y, Z, alpha=0.3, cmap='viridis')

# Plot basis vectors
ax.quiver(0, 0, 0, v1[0], v1[1], v1[2], color='r', arrow_length_ratio=0.15, linewidth=3)
ax.quiver(0, 0, 0, v2[0], v2[1], v2[2], color='g', arrow_length_ratio=0.15, linewidth=3)

ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
ax.set_title('Span of two 3D vectors')
plt.show()

# Example
v1 = np.array([1, 0, 0])
v2 = np.array([0, 1, 1])
visualize_span_3d(v1, v2)

18. Interactive linear combination visualizer:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider

def interactive_linear_combination(v1, v2):
"""Interactive visualization of linear combinations"""
fig, ax = plt.subplots(figsize=(10, 8))
plt.subplots_adjust(bottom=0.25)

# Initial coefficients
c1_init, c2_init = 1.0, 1.0

# Plot setup
ax.set_xlim(-5, 5)
ax.set_ylim(-5, 5)
ax.set_aspect('equal')
ax.grid(True, alpha=0.3)
ax.axhline(y=0, color='k', linewidth=0.8)
ax.axvline(x=0, color='k', linewidth=0.8)

# Plot basis vectors
ax.quiver(0, 0, v1[0], v1[1], angles='xy', scale_units='xy', scale=1,
color='r', width=0.015, label='v1')
ax.quiver(0, 0, v2[0], v2[1], angles='xy', scale_units='xy', scale=1,
color='g', width=0.015, label='v2')

# Initial result
result = c1_init * v1 + c2_init * v2
result_arrow, = ax.plot([0, result[0]], [0, result[1]], 'b-', linewidth=2)
result_point, = ax.plot([result[0]], [result[1]], 'bo', markersize=10)

# Sliders
ax_c1 = plt.axes([0.15, 0.15, 0.7, 0.03])
ax_c2 = plt.axes([0.15, 0.10, 0.7, 0.03])
slider_c1 = Slider(ax_c1, 'c1', -3.0, 3.0, valinit=c1_init)
slider_c2 = Slider(ax_c2, 'c2', -3.0, 3.0, valinit=c2_init)

def update(val):
c1 = slider_c1.val
c2 = slider_c2.val
result = c1 * v1 + c2 * v2
result_arrow.set_data([0, result[0]], [0, result[1]])
result_point.set_data([result[0]], [result[1]])
ax.set_title(f'Result: {c1:.2f}*v1 + {c2:.2f}*v2 = ({result[0]:.2f}, {result[1]:.2f})')
fig.canvas.draw_idle()

slider_c1.on_changed(update)
slider_c2.on_changed(update)

ax.legend()
update(None)
plt.show()

# Example
v1 = np.array([1, 0.5])
v2 = np.array([0.5, 1])
interactive_linear_combination(v1, v2)

Chapter Summary

This chapter established the core conceptual framework of linear algebra:

Concept Definition Intuition
Linear combination Weighted sum of vectors
Span All possible linear combinations All reachable positions
Linear independence Only zero solution No redundancy
Basis Independent + spans Smallest complete set
Dimension Size of basis Degrees of freedom
Subspace Contains zero + closed Space within a space

These concepts will pervade all of linear algebra:

  • Chapter 3: The span of a matrix's column vectors is the column space
  • Chapter 4: Determinants determine linear independence
  • Chapter 5: The solution space of linear systems is a subspace
  • Chapter 6: Eigenvectors form special bases
  • Chapter 7: Orthogonal bases simplify calculations
  • Chapter 9: SVD gives the "optimal" basis

Preview: Next Chapter

"Matrices as Linear Transformations"

Matrices aren't just tables of numbers — they are agents of transformation!

We will explore: - The geometric meaning of matrix-vector multiplication - Matrix representations of rotation, scaling, shearing, projection - Matrix multiplication = composition of transformations - Determinant = how transformation affects area/volume

Get ready to change your view of matrices!

References

  1. Strang, G. (2019). Linear Algebra and Learning from Data. Chapter 1.
  2. 3Blue1Brown. Essence of Linear Algebra, Chapters 2-3. [YouTube]
  3. Axler, S. (2015). Linear Algebra Done Right. Chapter 1-2.
  4. Boyd, S., & Vandenberghe, L. (2018). Introduction to Applied Linear Algebra. Chapter 2-5.
  5. Horn, R. A., & Johnson, C. R. (2012). Matrix Analysis. Chapter 0.

Next Chapter: "Matrices as Linear Transformations"

Previous Chapter: ← "The Essence of Vectors"


This is Chapter 2 of the 18-chapter "Essence of Linear Algebra" series.

  • Post title:Essence of Linear Algebra (2): Linear Combinations and Vector Spaces
  • Post author:Chen Kai
  • Create time:2019-01-09 14:15:00
  • Post link:https://www.chenk.top/chapter-02-linear-combinations-and-vector-spaces/
  • Copyright Notice:All articles in this blog are licensed under BY-NC-SA unless stating additionally.
 Comments