Ran Wei/ Linear Algebra
中文
Linear Algebra · Vectors and linear systems

Module 1Vectors and dot products

Add and scale vectors, measure their lengths, and use a dot product to compare directions.

65 minYou need School algebra and the Pythagorean theorem

In this module you will

  • Interpret a column of numbers as a displacement or a list of measurements
  • Use linear combinations to assemble a vector
  • Compute lengths, angles and dot products
1

From a displacement to a column

Walk three metres east and four metres north. The displacement is the column vector v=(34).\mathbf v=\begin{pmatrix}3\\4\end{pmatrix}\mathclose{\text{.}} Moving the arrow to another starting point leaves the displacement the same. The entries are coordinates relative to two chosen axes.

A vector can also hold data. If the coordinates are temperatures at two stations, subtracting two days gives the change at each station. You can add vectors with the same coordinate convention and multiply a vector by a scalar, a single number. Multiplying by a negative number reverses the direction.

Example 1.1Combining moves✓ Checked

Take u=(2,1)T\mathbf u=(2,1)^\mathsf T and v=(−1,3)T.\mathbf v=(-1,3)^\mathsf T\mathclose{\text{.}} Two copies of u\mathbf u followed by one v\mathbf v give 2u+v=(4,2)T+(−1,3)T=(3,5)T.2\mathbf u+\mathbf v=(4,2)^\mathsf T+(-1,3)^\mathsf T=(3,5)^\mathsf T\mathclose{\text{.}} A sum of scaled vectors is a linear combination.

Try it

Change the components of the two vectors. Compare their sum and dot product. Try perpendicular vectors, then point both in the same direction.

2

Length and angle

The dot product u⋅v\mathbf u\cdot\mathbf v pairs corresponding entries and adds their products. The Euclidean norm is ∥v∥=v⋅v.\|\mathbf v\|=\sqrt{\mathbf v\cdot\mathbf v}\mathclose{\text{.}} A vector of length one is a unit vector.

For nonzero vectors the angle θ\theta satisfies

cos⁡θ=u⋅v∥u∥∥v∥.\cos\theta=\frac{\mathbf u\cdot\mathbf v}{\|\mathbf u\|\|\mathbf v\|}.

To see why, expand ∥u−v∥2\|\mathbf u-\mathbf v\|^2 as a dot product, then compare with the cosine rule for the triangle. At a right angle the dot product is zero. A negative dot product means the angle is obtuse. Two vectors with zero dot product are orthogonal. The zero vector is orthogonal to every vector, but it has no direction and no angle with another vector.

Example 1.2A direction and a length✓ Checked

For u=(1,2)T\mathbf u=(1,2)^\mathsf T and v=(2,−1)T,\mathbf v=(2,-1)^\mathsf T\mathclose{\text{,}} the dot product is 1⋅2+2(−1)=0.1\cdot2+2(-1)=0\mathclose{\text{.}} Both have length 5,\sqrt5\mathclose{\text{,}} so the nonzero vectors meet at a right angle.

Watch out

The sign of the dot product says something about the angle, not the length. The vector (−3,−4)T(-3,-4)^\mathsf T still has length 5.5\mathclose{\text{.}}

Compute itExact vector arithmetic

SymPy uses a column when you pass a list to Matrix.

Python
from sympy import Matrix

v = Matrix([3, 4])
print(v.norm())
print(list(v / v.norm()))
Output
5
[3/5, 4/5]
3

Exercises

Exercise 1.1★A combination

Find 3(1,−2)T−2(2,1)T.3(1,-2)^\mathsf T-2(2,1)^\mathsf T\mathclose{\text{.}}

Show solution✓ Checked

Compute entry by entry. The first coordinate is 3−4=−13-4=-1 and the second is −6−2=−8.-6-2=-8\mathclose{\text{.}}

Exercise 1.2★★Find a perpendicular vector

Find a unit vector perpendicular to (3,4)T.(3,4)^\mathsf T\mathclose{\text{.}}

Show solution✓ Checked

The vector (−4,3)T(-4,3)^\mathsf T has dot product −12+12=0-12+12=0 with the original and length 5.5\mathclose{\text{.}} Divide it by 5.5\mathclose{\text{.}} The opposite unit vector also works.

Exercise 1.3★★★Dot product from lengths

If ∥u∥=2,\|\mathbf u\|=2\mathclose{\text{,}} ∥v∥=3\|\mathbf v\|=3 and ∥u+v∥2=7,\|\mathbf u+\mathbf v\|^2=7\mathclose{\text{,}} find the dot product.

Show solution✓ Checked

Expanding the squared norm gives 7=4+2u⋅v+9.7=4+2\mathbf u\cdot\mathbf v+9\mathclose{\text{.}} Thus u⋅v=−3.\mathbf u\cdot\mathbf v=-3\mathclose{\text{.}}

4

Check yourself

1
What is the length of (0,−5)T?(0,-5)^\mathsf T\mathclose{\text{?}}
2
Which vector is orthogonal to (2,1)T?(2,1)^\mathsf T\mathclose{\text{?}}
3
When is v/∥v∥\mathbf v/\|\mathbf v\| defined?
Finished this module?