Skip to main content
© 2026 ePowerAI — instrumented learning, no login required.
CoursesContact
ePOWERAI
CoursesContact
Week 1: Vectors and Linear Combinations
Linear Algebra
01Start Here: Python and the Math the Labs Use
02Week 1: Vectors and Linear Combinations
03Week 2: Linear Transformations and Matrices
04Week 3: Elimination and LU Factorization
05Week 4: Determinants
06Week 5: Vector Spaces, Independence, and Basis
07Week 6: The Four Fundamental Subspaces
08Week 7: Orthogonality and Projections
09Week 8: Least Squares and QR
10Week 9: Eigenvalues and Eigenvectors
11Week 10: Diagonalization and Markov Matrices
12Week 11: Differential Equations
13Week 12: Symmetric and Positive Definite Matrices
14Week 13: The SVD and Complex Matrices
15Week 14: The Fourier Matrix, FFT, and PCA
Week 01· Linear Algebra11 min read

Week 1: Vectors and Linear Combinations

Learning Outcomes
  • Represent vectors in Rn\mathbb{R}^nRn and perform vector addition and scalar multiplication
  • Compute linear combinations of vectors and interpret them geometrically
  • Compute the dot product and use it to find vector length and the angle between vectors
  • Determine whether two vectors are orthogonal using the dot product
Prerequisites

Background knowledge assumed:

  • Basic algebra (solving equations, working with variables)
  • Comfort with coordinate geometry in two and three dimensions

Recommended: Review the Course Index for an overview of the learning path.

Vectors as Objects#

A vector is the basic object of linear algebra. In Rn\mathbb{R}^nRn, a vector is an ordered list of nnn real numbers. We write it as a column:

v=(v1v2⋮vn)v = \begin{pmatrix} v_1 \\ v_2 \\ \vdots \\ v_n \end{pmatrix}v=​v1​v2​⋮vn​​​

Each entry viv_ivi​ is a component (or coordinate). Two vectors are equal only when every corresponding component matches. The space Rn\mathbb{R}^nRn is the set of all such nnn-tuples.

Geometry in the plane. In R2\mathbb{R}^2R2, the vector v=(v1v2)v = \begin{pmatrix} v_1 \\ v_2 \end{pmatrix}v=(v1​v2​​) can be drawn as an arrow from the origin (0,0)(0,0)(0,0) to the point (v1,v2)(v_1, v_2)(v1​,v2​). The tip of the arrow is the point with those coordinates; the shaft is the directed segment from the origin. For example,

v=(32)v = \begin{pmatrix} 3 \\ 2 \end{pmatrix}v=(32​)

points three units right and two units up. In R3\mathbb{R}^3R3, the same idea holds across three axes. For n>3n > 3n>3 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 Rn\mathbb{R}^nRn 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

u=(u1⋮un),v=(v1⋮vn),u = \begin{pmatrix} u_1 \\ \vdots \\ u_n \end{pmatrix}, \quad v = \begin{pmatrix} v_1 \\ \vdots \\ v_n \end{pmatrix},u=​u1​⋮un​​​,v=​v1​⋮vn​​​,

then

u+v=(u1+v1⋮un+vn).u + v = \begin{pmatrix} u_1 + v_1 \\ \vdots \\ u_n + v_n \end{pmatrix}.u+v=​u1​+v1​⋮un​+vn​​​.

Geometrically, place the tail of vvv at the tip of uuu, or the other way around; the two arrows form a parallelogram, and u+vu + vu+v is its diagonal. This picture is the parallelogram law.

Scalar multiplication multiplies every component by a real number ccc:

cv=(cv1⋮cvn).cv = \begin{pmatrix} c v_1 \\ \vdots \\ c v_n \end{pmatrix}.cv=​cv1​⋮cvn​​​.

If c>1c > 1c>1, the arrow stretches; if 0<c<10 < c < 10<c<1, it shrinks; if c<0c < 0c<0, it flips direction and scales by ∣c∣|c|∣c∣. The zero vector 000 has every component zero; it is the unique vector with v+0=vv + 0 = vv+0=v for all vvv.

Worked example. Let u=(12)u = \begin{pmatrix} 1 \\ 2 \end{pmatrix}u=(12​) and v=(3−1)v = \begin{pmatrix} 3 \\ -1 \end{pmatrix}v=(3−1​). Then

u+v=(41),2u=(24),−v=(−31).u + v = \begin{pmatrix} 4 \\ 1 \end{pmatrix}, \qquad 2u = \begin{pmatrix} 2 \\ 4 \end{pmatrix}, \qquad -v = \begin{pmatrix} -3 \\ 1 \end{pmatrix}.u+v=(41​),2u=(24​),−v=(−31​).

Algebra rules (we state them without proof; they follow from the same rules for real numbers, applied component-wise):

  • Commutativity of addition: u+v=v+uu + v = v + uu+v=v+u
  • Associativity of addition: (u+v)+w=u+(v+w)(u + v) + w = u + (v + w)(u+v)+w=u+(v+w)
  • Distributivity: c(u+v)=cu+cvc(u + v) = cu + cvc(u+v)=cu+cv and (c+d)u=cu+du(c + d)u = cu + du(c+d)u=cu+du
  • Compatibility of scalars: (cd)u=c(du)(cd)u = c(du)(cd)u=c(du)
  • Identity scalars: 1⋅u=u1 \cdot u = u1⋅u=u and 0⋅u=00 \cdot u = 00⋅u=0

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.

Exercise · Multiple choice

If u = (3, -1) and v = (2, 4), what is u + v?

(1, 3)
(5, 3)
(6, -4)
(5, 5)

Linear Combinations and Span#

A linear combination of vectors v1,v2,…,vkv_1, v_2, \ldots, v_kv1​,v2​,…,vk​ is any vector of the form

c1v1+c2v2+⋯+ckvk,c_1 v_1 + c_2 v_2 + \dots + c_k v_k,c1​v1​+c2​v2​+⋯+ck​vk​,

where the coefficients c1,…,ckc_1, \ldots, c_kc1​,…,ck​ are real scalars.

Worked example. Take

v1=(11),v2=(1−1)v_1 = \begin{pmatrix} 1 \\ 1 \end{pmatrix}, \quad v_2 = \begin{pmatrix} 1 \\ -1 \end{pmatrix}v1​=(11​),v2​=(1−1​)

in R2\mathbb{R}^2R2. Can we reach the target b=(42)b = \begin{pmatrix} 4 \\ 2 \end{pmatrix}b=(42​)? We need scalars c1,c2c_1, c_2c1​,c2​ such that

c1v1+c2v2=b⟺(c1+c2c1−c2)=(42).c_1 v_1 + c_2 v_2 = b \quad\Longleftrightarrow\quad \begin{pmatrix} c_1 + c_2 \\ c_1 - c_2 \end{pmatrix} = \begin{pmatrix} 4 \\ 2 \end{pmatrix}.c1​v1​+c2​v2​=b⟺(c1​+c2​c1​−c2​​)=(42​).

Adding the two component equations: 2c1=62c_1 = 62c1​=6, so c1=3c_1 = 3c1​=3. Subtracting: 2c2=22c_2 = 22c2​=2, so c2=1c_2 = 1c2​=1. Check:

3(11)+1(1−1)=(33)+(1−1)=(42).3\begin{pmatrix} 1 \\ 1 \end{pmatrix} + 1\begin{pmatrix} 1 \\ -1 \end{pmatrix} = \begin{pmatrix} 3 \\ 3 \end{pmatrix} + \begin{pmatrix} 1 \\ -1 \end{pmatrix} = \begin{pmatrix} 4 \\ 2 \end{pmatrix}.3(11​)+1(1−1​)=(33​)+(1−1​)=(42​).

So b=3v1+v2b = 3v_1 + v_2b=3v1​+v2​ is a linear combination of v1v_1v1​ and v2v_2v2​.

Span. The span of a set of vectors {v1,…,vk}\{v_1, \ldots, v_k\}{v1​,…,vk​} is the set of all linear combinations of those vectors:

span⁡{v1,…,vk}={c1v1+⋯+ckvk:ci∈R}.\operatorname{span}\{v_1, \ldots, v_k\} = \{ c_1 v_1 + \cdots + c_k v_k : c_i \in \mathbb{R} \}.span{v1​,…,vk​}={c1​v1​+⋯+ck​vk​:ci​∈R}.

If the span is all of Rn\mathbb{R}^nRn, the set is said to span Rn\mathbb{R}^nRn. In the example above, v1v_1v1​ and v2v_2v2​ are not parallel, so their span is the whole plane R2\mathbb{R}^2R2: every target in R2\mathbb{R}^2R2 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.

Two independent vectors spanning the plane, with b assembled as 3v1 + v2

The span of two non-parallel vectors is the whole plane. The target bbb is assembled as 3v1+v23v_1 + v_23v1​+v2​; the dashed edges of the parallelogram are the two component vectors.


The Dot Product#

The dot product (also called the inner product on Rn\mathbb{R}^nRn) of two vectors x,y∈Rnx, y \in \mathbb{R}^nx,y∈Rn is the scalar

x⋅y=∑i=1nxiyi=x1y1+x2y2+⋯+xnyn.x \cdot y = \sum_{i=1}^{n} x_i y_i = x_1 y_1 + x_2 y_2 + \cdots + x_n y_n.x⋅y=i=1∑n​xi​yi​=x1​y1​+x2​y2​+⋯+xn​yn​.

It is symmetric (x⋅y=y⋅xx \cdot y = y \cdot xx⋅y=y⋅x) and linear in each argument separately; both facts follow from writing the sums out component-wise.

Length (norm). The length or Euclidean norm of xxx is defined from the dot product with itself:

∥x∥=x⋅x=x12+⋯+xn2.\|x\| = \sqrt{x \cdot x} = \sqrt{x_1^2 + \cdots + x_n^2}.∥x∥=x⋅x​=x12​+⋯+xn2​​.

This is the ordinary distance from the origin to the tip of xxx. For example, ∥(3,4)∥=9+16=5\|(3,4)\| = \sqrt{9 + 16} = 5∥(3,4)∥=9+16​=5.

Angle between vectors. The geometric content of the dot product is the angle θ\thetaθ between two nonzero vectors:

cos⁡θ=x⋅y∥x∥ ∥y∥,\cos\theta = \dfrac{x \cdot y}{\|x\|\,\|y\|},cosθ=∥x∥∥y∥x⋅y​,

with θ\thetaθ taken in [0,π][0, \pi][0,π]. To see why, draw the triangle with vertices 000, xxx, and yyy: the side opposite θ\thetaθ has length ∥x−y∥\|x - y\|∥x−y∥, so by the law of cosines (a standard plane-geometry identity),

∥x−y∥2=∥x∥2+∥y∥2−2∥x∥ ∥y∥cos⁡θ.\|x - y\|^2 = \|x\|^2 + \|y\|^2 - 2\|x\|\,\|y\|\cos\theta.∥x−y∥2=∥x∥2+∥y∥2−2∥x∥∥y∥cosθ.

Expanding the same length with the dot product instead gives

∥x−y∥2=(x−y)⋅(x−y)=∥x∥2−2 x⋅y+∥y∥2.\|x - y\|^2 = (x - y) \cdot (x - y) = \|x\|^2 - 2\,x\cdot y + \|y\|^2.∥x−y∥2=(x−y)⋅(x−y)=∥x∥2−2x⋅y+∥y∥2.

Equating the two expressions, the ∥x∥2\|x\|^2∥x∥2 and ∥y∥2\|y\|^2∥y∥2 terms cancel, leaving x⋅y=∥x∥ ∥y∥cos⁡θx \cdot y = \|x\|\,\|y\|\cos\thetax⋅y=∥x∥∥y∥cosθ.

Worked example. Let x=(10)x = \begin{pmatrix} 1 \\ 0 \end{pmatrix}x=(10​) and y=(11)y = \begin{pmatrix} 1 \\ 1 \end{pmatrix}y=(11​). Then

x⋅y=1⋅1+0⋅1=1,∥x∥=1,∥y∥=2.x \cdot y = 1 \cdot 1 + 0 \cdot 1 = 1, \quad \|x\| = 1, \quad \|y\| = \sqrt{2}.x⋅y=1⋅1+0⋅1=1,∥x∥=1,∥y∥=2​.

So

cos⁡θ=11⋅2=12,θ=45∘=π4.\cos\theta = \frac{1}{1 \cdot \sqrt{2}} = \frac{1}{\sqrt{2}}, \quad \theta = 45^\circ = \frac{\pi}{4}.cosθ=1⋅2​1​=2​1​,θ=45∘=4π​.

That matches the picture: the unit vector along the xxx-axis and the diagonal of the unit square meet at 45∘45^\circ45∘.

Exercise · Fill in the blank

Compute the dot product of u = (1, 2, 3) and v = (4, -1, 2).


Orthogonality#

Two vectors xxx and yyy are orthogonal (written x⊥yx \perp yx⊥y) when their dot product is zero:

x⋅y=0  ⟺  x⊥yx \cdot y = 0 \iff x \perp yx⋅y=0⟺x⊥y

(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, x⋅y=0x \cdot y = 0x⋅y=0 forces cos⁡θ=0\cos\theta = 0cosθ=0, i.e. θ=90∘\theta = 90^\circθ=90∘.

Examples. In R2\mathbb{R}^2R2, (10)\begin{pmatrix} 1 \\ 0 \end{pmatrix}(10​) and (01)\begin{pmatrix} 0 \\ 1 \end{pmatrix}(01​) are orthogonal. So are (21)\begin{pmatrix} 2 \\ 1 \end{pmatrix}(21​) and (−12)\begin{pmatrix} -1 \\ 2 \end{pmatrix}(−12​), because 2⋅(−1)+1⋅2=02\cdot(-1) + 1\cdot 2 = 02⋅(−1)+1⋅2=0. In R3\mathbb{R}^3R3, the standard basis vectors e1,e2,e3e_1, e_2, e_3e1​,e2​,e3​ are pairwise orthogonal.

Pythagorean theorem for vectors. When x⊥yx \perp yx⊥y, lengths add in the familiar squared form:

∥x+y∥2=∥x∥2+∥y∥2.\|x + y\|^2 = \|x\|^2 + \|y\|^2.∥x+y∥2=∥x∥2+∥y∥2.

Why. Expand the left side with the dot product:

∥x+y∥2=(x+y)⋅(x+y)=∥x∥2+2 x⋅y+∥y∥2.\|x + y\|^2 = (x + y) \cdot (x + y) = \|x\|^2 + 2\, x \cdot y + \|y\|^2.∥x+y∥2=(x+y)⋅(x+y)=∥x∥2+2x⋅y+∥y∥2.

If x⋅y=0x \cdot y = 0x⋅y=0, the cross term vanishes and we recover ∥x∥2+∥y∥2\|x\|^2 + \|y\|^2∥x∥2+∥y∥2. Conversely, if the Pythagorean identity holds, then x⋅y=0x \cdot y = 0x⋅y=0, so the vectors are orthogonal. This is the clean algebraic form of the classical theorem in the plane, and it holds in every Rn\mathbb{R}^nRn.

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#

Question 1 of 4

What is the length (norm) of the vector v = (3, 4)?

5
7
3.5
12

Browser lab: dot product, length, and angle#

Compute the dot product, length, and angle between two vectors, then visualize them.

python · runs in browser
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 Rn\mathbb{R}^nRn 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.
← Previous
Start Here: Python and the Math the Labs Use
Next →
Week 2: Linear Transformations and Matrices
On this page
  • Vectors as Objects
  • Vector Addition and Scalar Multiplication
  • Linear Combinations and Span
  • The Dot Product
  • Orthogonality
  • Knowledge check
  • Browser lab: dot product, length, and angle
  • Done when
  • Further Reading