Vectors as Objects#
A vector is the basic object of linear algebra. In , a vector is an ordered list of real numbers. We write it as a column:
Each entry is a component (or coordinate). Two vectors are equal only when every corresponding component matches. The space is the set of all such -tuples.
Geometry in the plane. In , the vector can be drawn as an arrow from the origin to the point . The tip of the arrow is the point with those coordinates; the shaft is the directed segment from the origin. For example,
points three units right and two units up. In , the same idea holds across three axes. For we keep the algebraic definition and drop the picture; addition, scaling, and the dot product still work component-wise, exactly as in the plane. Those are the dimensions where data and machine learning actually live.
Vectors are not the same as free-floating points: a point has a location, while a vector carries a direction and magnitude of its own, independent of where it is drawn. Its components are the coordinates the vector receives in a chosen basis; in this course we always fix the standard basis of unless we say otherwise.
Vector Addition and Scalar Multiplication#
Two fundamental operations turn the set of vectors into a vector space: addition and scalar multiplication.
Addition is component-wise. If
then
Geometrically, place the tail of at the tip of , or the other way around; the two arrows form a parallelogram, and is its diagonal. This picture is the parallelogram law.
Scalar multiplication multiplies every component by a real number :
If , the arrow stretches; if , it shrinks; if , it flips direction and scales by . The zero vector has every component zero; it is the unique vector with for all .
Worked example. Let and . Then
Algebra rules (we state them without proof; they follow from the same rules for real numbers, applied component-wise):
- Commutativity of addition:
- Associativity of addition:
- Distributivity: and
- Compatibility of scalars:
- Identity scalars: and
These rules are the entire algebraic interface of a vector space. Everything else in the course — linear combinations, matrices as maps, bases, and projections — is built from them.
If u = (3, -1) and v = (2, 4), what is u + v?
Linear Combinations and Span#
A linear combination of vectors is any vector of the form
where the coefficients are real scalars.
Worked example. Take
in . Can we reach the target ? We need scalars such that
Adding the two component equations: , so . Subtracting: , so . Check:
So is a linear combination of and .
Span. The span of a set of vectors is the set of all linear combinations of those vectors:
If the span is all of , the set is said to span . In the example above, and are not parallel, so their span is the whole plane : every target in is some linear combination of them. If instead both vectors lie on the same line through the origin, their span is only that line.
Span is the geometric answer to “what can these vectors generate?” Week 5 refines this into the notions of linear independence and bases.
The span of two non-parallel vectors is the whole plane. The target is assembled as ; the dashed edges of the parallelogram are the two component vectors.
The Dot Product#
The dot product (also called the inner product on ) of two vectors is the scalar
It is symmetric () and linear in each argument separately; both facts follow from writing the sums out component-wise.
Length (norm). The length or Euclidean norm of is defined from the dot product with itself:
This is the ordinary distance from the origin to the tip of . For example, .
Angle between vectors. The geometric content of the dot product is the angle between two nonzero vectors:
with taken in . To see why, draw the triangle with vertices , , and : the side opposite has length , so by the law of cosines (a standard plane-geometry identity),
Expanding the same length with the dot product instead gives
Equating the two expressions, the and terms cancel, leaving .
Worked example. Let and . Then
So
That matches the picture: the unit vector along the -axis and the diagonal of the unit square meet at .
Compute the dot product of u = (1, 2, 3) and v = (4, -1, 2).
Orthogonality#
Two vectors and are orthogonal (written ) when their dot product is zero:
(for nonzero vectors; the zero vector is orthogonal to every vector by the same algebraic definition). Orthogonality is the coordinate-free way to say “perpendicular”: from the angle formula, forces , i.e. .
Examples. In , and are orthogonal. So are and , because . In , the standard basis vectors are pairwise orthogonal.
Pythagorean theorem for vectors. When , lengths add in the familiar squared form:
Why. Expand the left side with the dot product:
If , the cross term vanishes and we recover . Conversely, if the Pythagorean identity holds, then , so the vectors are orthogonal. This is the clean algebraic form of the classical theorem in the plane, and it holds in every .
Orthogonality will reappear constantly: orthogonal projections (Week 7), orthonormal bases and the QR idea later in the course, and least-squares solutions where residual vectors are orthogonal to the column space.
Knowledge check#
What is the length (norm) of the vector v = (3, 4)?
Browser lab: dot product, length, and angle#
Compute the dot product, length, and angle between two vectors, then visualize them.
import numpy as np
import matplotlib.pyplot as plt
u = np.array([2, 1])
v = np.array([1, 3])
dot = np.dot(u, v)
length_u = np.linalg.norm(u)
length_v = np.linalg.norm(v)
cos_theta = dot / (length_u * length_v)
angle_deg = np.degrees(np.arccos(cos_theta))
print(f"u . v = {dot}")
print(f"|u| = {length_u:.3f}, |v| = {length_v:.3f}")
print(f"angle between u and v = {angle_deg:.1f} degrees")
fig, ax = plt.subplots(figsize=(5, 5))
ax.quiver(0, 0, u[0], u[1], angles="xy", scale_units="xy", scale=1, color="tab:blue", label="u")
ax.quiver(0, 0, v[0], v[1], angles="xy", scale_units="xy", scale=1, color="tab:orange", label="v")
ax.set_xlim(-1, 4)
ax.set_ylim(-1, 4)
ax.set_aspect("equal")
ax.legend()
ax.set_title("Vectors u and v")
plt.show()
print("Notice: u·v = 5 gives cos θ ≈ 0.707, so the angle between the arrows is 45°.")
Done when#
You can add and scale vectors, express a target vector as an explicit linear combination of two given vectors (or show it is impossible), and use the dot product to report a length, an angle, and orthogonality — all without notes. Check it against the browser lab: for u = (2, 1) and v = (1, 3) the printed output must read u . v = 5, |u| = 2.236, |v| = 3.162, and angle ... = 45.0 degrees, and each number must match your own hand calculation.
Further Reading#
- Gilbert Strang, Introduction to Linear Algebra (5th ed., Wellesley-Cambridge Press, 2016). Chapters 1–2 cover vectors, linear combinations, and dot products with exceptional geometric clarity.
- David C. Lay, Steven R. Lay & Judi J. McDonald, Linear Algebra and Its Applications (6th ed., Pearson, 2021). Chapter 1 provides a thorough treatment of vectors in with abundant exercises.
- Stephen Boyd & Lieven Vandenberghe, Introduction to Applied Linear Algebra (Cambridge University Press, 2018). Chapters 1–3 present vectors and linear combinations from an applied data-science perspective. Freely available at vmls-book.stanford.edu.
- 3Blue1Brown, Essence of Linear Algebra (YouTube playlist). The first three videos (“Vectors, what even are they?”, “Linear combinations, span, and basis vectors”, “Linear transformations and matrices”) are outstanding geometric companions to this week’s material.
- Khan Academy, Vectors and Spaces module. Free interactive exercises on vector addition, scalar multiplication, and linear combinations.