Saturday, 4 May 2019

Visualizing linear algebra: Vectors

Figure 1: Numeric and geometric
representation of a 2D vector
This is Part 1 in a series on linear algebra [1].

Geometrically, a vector is an arrow that has two components: a length and a direction. The yellow arrow in Figure 1 lives in a 2D vector space defined by a horizontal (X) dimension and a vertical (Y) dimension and with the tail of the arrow at the origin.

An equivalent numeric representation is as an ordered list of numbers. As shown in Figure 1, the column stores the coordinates of the vector from top to bottom in order of dimension (i.e., X then Y). A 2D vector can be represented generally as:

[x]
[y]

Figure 2: Vector addition
Vectors, like numbers, can be added. Geometrically, considering the two vectors that are to be added as arrows, this is done by moving the second arrow such that its tail is at the head of the first arrow. The sum is itself an arrow which extends from the tail of the first arrow to the head of the second arrow. In Figure 2, the summed arrow is represented by the purple arrow extending from the origin.

In the numeric representation, the sum vector is calculated by adding the coordinates for each dimension. Generally:

[x1] + [x2] = [x1 + x2]
[y1]   [y2]   [y1 + y2]

Figure 3: Vector multiplication (scaling)
Vectors can also be multiplied by a number. This number is called a scalar since it scales the vector by that number. In Figure 3, the original arrow is scaled by 2.

In the numeric representation, the product vector is calculated by multiplying each coordinate by the scalar. Generally:

s * [x] = [s * x]
    [y]   [s * y]


Figure 4: Linear combination of scaled unit vectors
In a 2D coordinate system there are two special vectors: i-hat (î) is the unit vector in the horizontal (X) direction and j-hat (ĵ) is the unit vector in the vertical (Y) direction.

Each of the coordinates in any given vector can be considered as scalars that scale the unit vectors. In Figure 4, i-hat is flipped (since the scalar is negative) and scaled by a factor of 5 while j-hat is scaled by a factor of 2. That is, the yellow arrow is the sum of the two scaled unit arrows.

When any vectors are scaled and added in this way, the resulting expression is a linear combination of those scaled unit vectors (which is, itself, a vector as geometrically represented by the yellow arrow in Figure 4). Generally:

v =  +

The span of the unit vectors is the 2D plane (the set of all their possible linear combinations). That is, any point on the 2D plane can be reached by a unique scaling of the two unit vectors. This is also true for most pairs of vectors except those that reside on the same line (in which case their span is just the 1D line and so these vectors are linearly dependent). The unit vectors are linearly independent and, for simplicity, are often chosen as the basis vectors for a 2D space as in Figure 4. This general idea also extends to three and higher dimensions where, for example, the span of the three unit vectors is the 3D volume.

Next up: matrices

--

[1] The figures and examples of the posts in this series are based on the Essence of Linear Algebra series by 3Blue1Brown.

No comments:

Post a Comment