Linear Algebra / Unit 1, Vectors / Topic 1.2
Unit 1. Vectors
This topic shows how to calculate the length of a vector and introduces the dot product, which takes two vectors and gives one number. The dot product is used to find the angle between two vectors and to test whether two vectors are perpendicular.
You need Topic 1.1 for this topic. You also need the Pythagorean theorem and the cosine function.
The vector v = (3, 4) goes 3 units to the right and 4 units up. These two moves are the legs of a right triangle, and the arrow is the hypotenuse. The Pythagorean theorem gives the length of the arrow:
|v| = √3² + 4²the Pythagorean theorem|v| = √25add the squares|v| = 5take the square rootThe length of a vector is written with bars, |v|. It is also called the magnitude of the vector. For any vector with components v₁ and v₂,
|v| = √v₁² + v₂²The length is a scalar, and it is never negative. Only the zero vector has a length of 0.
Multiplying a vector by a scalar c multiplies its length by the size of c. The vector 2v is twice as long as v. The vector −2v is also twice as long as v, because the negative sign changes only the direction.
A vector with a length of 1 is called a unit vector. To make a unit vector that points in the direction of v, divide v by its length. For v = (3, 4), the unit vector is (3/5, 4/5), which is (0.6, 0.8). A unit vector gives a direction without a size.
The distance between two points is the length of the vector from one point to the other. From (1, 2) to (4, 6), the vector is (3, 4), so the distance is 5.
The dot product of two vectors is found by multiplying the matching components and adding the results.
u · v = u₁v₁ + u₂v₂For example,
41 · 23 = (4)(2) + (1)(3)multiply the matching components41 · 23 = 11add the productsThe dot product of two vectors is a number. It is not a vector. This is the most common point of confusion with the dot product.
The dot product of a vector with itself is the square of its length:
v · v = v₁² + v₂² = |v|²The dot product measures how much two vectors point in the same direction. If θ is the angle between u and v, then
u · v = |u| |v| cos θThe two formulas for the dot product always give the same number. The first formula uses the components. The second formula uses the lengths and the angle.
The sign of the dot product gives information about the angle, because the lengths are positive and only cos θ can be negative.
| Dot product | Angle between the vectors |
|---|---|
| Positive | Less than 90° |
| Zero | Exactly 90°. The vectors are perpendicular. |
| Negative | Greater than 90° |
Try it: the dot product
Drag the tip of the blue arrow or the tip of the red arrow. The green arrow is the shadow of u on the line of v. Press Play to turn u through a full circle and observe the sign of the dot product.
To find the angle between two vectors, calculate the dot product from the components, divide by the two lengths, and take the inverse cosine.
cos θ = (u · v)/(|u| |v|)For u = (4, 1) and v = (2, 3):
u · v = (4)(2) + (1)(3) = 11the dot product|u| = √4² + 1² = √17the length of u|v| = √2² + 3² = √13the length of vcos θ = 11/√221 = 0.740divide the dot product by the two lengths, with √17 √13 = √221θ = 42.3°take the inverse cosineTwo vectors that are not zero are perpendicular exactly when their dot product is 0. For example:
(2, 3) · (−3, 2) = (2)(−3) + (3)(2)multiply the matching components(2, 3) · (−3, 2) = −6 + 6 = 0add the productsThe dot product is 0, so these two vectors are perpendicular. No angle has to be calculated.
In the drawing, the green arrow is the shadow of u on the line of v. Its signed length is called the component of u along v. From the right triangle in the drawing, this component is |u| cos θ. Using the dot product,
component of u along v = (u · v) / |v|The green arrow is called the projection of u onto v. It is the component multiplied by the unit vector in the direction of v:
projection of u onto v = (u · v)/(v · v) vWork is the best known example. When a constant force F acts on an object that moves through a displacement d, the work done by the force is
W = F · d = |F| |d| cos θOnly the component of the force along the displacement does work. A force that is perpendicular to the displacement does no work, because the dot product is 0. This is the reason the normal force does no work on a block that slides along a level floor.
| Term | Meaning |
|---|---|
| Length | |v| = √v₁² + v₂² |
| Unit vector | A vector with a length of 1 |
| Dot product | u · v = u₁v₁ + u₂v₂ = |u| |v| cos θ |
| Perpendicular | u · v = 0 |
| Projection | The shadow of one vector on the line of another vector |
Work each problem on paper first. Then open the answer to check your work.
length = √(−5)² + 12²the Pythagorean theoremlength = √25 + 144 = √169add the squareslength = 13take the square root
length = √6² + 8² = √100 = 10the length of the vectorunit vector = (6/10, 8/10) = (0.6, 0.8)divide each component by the length
(3, −2) · (1, 5) = (3)(1) + (−2)(5)multiply the matching components(3, −2) · (1, 5) = 3 − 10 = −7add the products
The dot product is negative, so the angle between the vectors is greater than 90°.
dot product = (1)(1) + (0)(1) = 1multiply the matching components and addlength of (1, 0) = 1length of (1, 1) = √1² + 1² = √2cos θ = 1/√2divide the dot product by the two lengthsθ = 45°take the inverse cosine
(2)(3) + (k)(−6) = 0the dot product must be 06 − 6k = 0multiplyk = 1add 6k to both sides, then divide by 6
W = F · dthe work done by a constant forceW = (10)(4) + (5)(0)multiply the matching componentsW = 40 Jadd the products
The vertical part of the force does no work, because the cart does not move vertically.
Python reads the code one line at a time, from the top to the bottom. The equals sign stores the value on its right under the name on its left, and print shows a result. A vector is written as np.array([3, 4]), where np stands for NumPy, the part of Python that works with vectors and matrices.
The instruction np.linalg.norm calculates the length of a vector. The word norm is another name for length. The name of the vector goes inside the parentheses.
Python
The result is 5.0, because the square root of 3² + 4² is 5. Python writes 5.0 and not 5, because it stores the result of a square root as a decimal number.
Now change the vector so that the code prints the length of (5, 12).
Python
The instruction np.dot calculates the dot product of two vectors. The names of the two vectors go inside the parentheses, with a comma between them.
Python
The result is 10, because (3)(2) + (4)(1) = 10.
From Part 3 of this topic, two vectors are perpendicular when their dot product is 0. In the next box, change v so that it is perpendicular to u. Do not change u, and do not use the zero vector.
Python
The angle comes from the equation cos θ = (u · v) / (|u| |v|) in Part 3 of this topic. The code below does the calculation in three steps. The third line calculates cos θ and stores it under the name c. The fourth line finds the angle with np.arccos, which is the inverse cosine. Python gives that angle in radians, so np.degrees changes it to degrees.
Python
The angle between (3, 4) and (2, 1) is about 26.6 degrees.
Now change u and v so that the code finds the angle between (1, 0) and (1, 1). Before you press Run, decide what the angle should be from a sketch.
Python
Python may print 45.00000000000001 and not 45. A computer stores most decimal numbers with a very small rounding error, so the last digits of a result can be slightly off. This is normal.
From Part 1 of this topic, dividing a vector by its length gives a unit vector in the same direction. The / sign divides each component by the number on its right.
Python
The first result is the unit vector [0.6 0.8]. The second result is its length, 1.0.
In the next box, change the code so that e is the unit vector in the direction of (6, −8).
Python
This quiz has 5 questions on this topic. A question asks you either to choose one answer or to type numbers. The page grades your answers and explains each one. A number can be typed as a whole number, a decimal, a fraction such as 1/3, or a calculation such as sqrt(18)/2 or arccos(1/2). The page shows the value of a calculation next to the box. Angles in a calculation are in degrees. The Calculator button under each question opens a calculator. Your answers are saved in your browser, so they are still on the page when you come back to it.
Choose how your answers are checked
1. Find the length of the vector (6, −8).
length = √6² + (−8)²the Pythagorean theoremlength = √100 = 10
2. Calculate the dot product of (2, −3) and (4, 1).
(2, −3) · (4, 1) = (2)(4) + (−3)(1)multiply the matching components(2, −3) · (4, 1) = 8 − 3 = 5add the products
3. Which of these vectors is perpendicular to (3, 2)?
Two vectors are perpendicular when their dot product is 0. For (−2, 3), the dot product is (3)(−2) + (2)(3) = 0. The other three dot products are 12, 5, and −13.
4. Find the angle between the vectors (0, 2) and (3, 3), in degrees.
dot product = (0)(3) + (2)(3) = 6length of (0, 2) = 2length of (3, 3) = √18cos θ = 6/2√18 = 0.707divide the dot product by the two lengthsθ = 45°take the inverse cosine
5. Which vector is the unit vector in the direction of (3, −4)?
length = √3² + (−4)² = 5unit vector = (3/5, −4/5) = (0.6, −0.8)divide each component by the lengthThe vector (−0.6, 0.8) also has the length 1, but it points in the opposite direction.