Scientia sine finibus

Linear Algebra / Unit 1, Vectors / Topic 1.4

Units and Topics

Unit 1. Vectors

1.4 Vectors in n Dimensions

This topic extends vectors to any number of components. A vector with more than three components cannot be drawn as an arrow, but all of the rules from Topics 1.1 and 1.2 still work.

You need Topics 1.1 and 1.2 for this topic.

1. Vectors with More Than Three Components

In Topic 1.1, a vector in the plane was a list of two numbers. In Topic 1.3, a vector in three dimensions was a list of three numbers. A vector can be a list of any number of numbers. A vector with n components is called a vector in n dimensions.

v = (v₁, v₂, …, vₙ)

The set of all vectors with n real components is written ℝⁿ. The plane is ℝ², and the space of three dimensions is ℝ³. The vector (1, 2, 0, −1) is in ℝ⁴.

Vectors with many components appear whenever several numbers describe one thing.

  • The motion of a particle at one instant is described by three position components and three velocity components. Together they form a vector in ℝ⁶.
  • A color on a screen is described by its amounts of red, green, and blue. This is a vector in ℝ³, although it is not an arrow in space.
  • The scores of one student on five tests form a vector in ℝ⁵.
  • The temperatures at 100 points along a metal rod form a vector in ℝ¹⁰⁰.

A vector in ℝ⁴ or ℝ¹⁰⁰ is not a statement about extra directions in physical space. The word dimension only counts how many numbers are in the list. The algebra does not need a drawing.

2. Addition and Scalar Multiplication

The two operations from Topic 1.1 work component by component, for any number of components.

u + v = (u₁ + v₁, u₂ + v₂, …, uₙ + vₙ) cv = (cv₁, cv₂, …, cvₙ)

For example, take u = (1, 2, 0, −1) and v = (3, −1, 4, 2) in ℝ⁴.

u + v = (4, 1, 4, 1) 2u = (2, 4, 0, −2) 2u − v = (−1, 5, −4, −4)

Two vectors can be added only when they have the same number of components. The sum of a vector in ℝ³ and a vector in ℝ⁴ is not defined.

The zero vector in ℝⁿ has n components, and all of them are 0. A linear combination has the same meaning as before: multiply each vector by a scalar, and add the results.

Try it: vectors as bars

Each vector has five components, and each component is drawn as one bar. Move the sliders to change a and b. The green bars show the linear combination au + bv. Press New vectors for a different pair.

3. Length, Dot Product, and Angle

The definitions from Topic 1.2 also extend to n components.

u · v = u₁v₁ + u₂v₂ + … + uₙvₙ |v| = √v · v = √v₁² + v₂² + … + vₙ²

For u = (1, 2, 0, −1) and v = (3, −1, 4, 2),

u · v = (1)(3) + (2)(−1) + (0)(4) + (−1)(2)multiply the matching componentsu · v = 3 − 2 + 0 − 2 = −1add the products|u| = √1 + 4 + 0 + 1 = √6 ≈ 2.45the length of u|v| = √9 + 1 + 16 + 4 = √30 ≈ 5.48the length of v

The angle

In two and three dimensions, the angle between two vectors can be measured in a drawing. In more dimensions there is no drawing, so the angle is defined by the same equation as in Topic 1.2.

cos θ = (u · v)/(|u| |v|)

For the two vectors above:

cos θ = −1/(√6 √30) ≈ −0.075divide the dot product by the two lengthsθ ≈ 94.3°take the inverse cosine

This definition works only if the right side is between −1 and 1, because a cosine cannot be outside that range. A result called the Cauchy-Schwarz inequality guarantees this for any two vectors:

|u · v| ≤ |u| |v|

For the example, the left side is 1 and the right side is about 13.4.

Orthogonal vectors

Two vectors are called orthogonal when their dot product is 0. In two and three dimensions, orthogonal means the same as perpendicular. For example, (1, 1, 1, 1) and (1, −1, 1, −1) are orthogonal, because 1 − 1 + 1 − 1 = 0. The word orthogonal is used in the rest of the course.

The triangle inequality

In a drawing, the sum u + v is the third side of a triangle with the sides u and v, and one side of a triangle cannot be longer than the other two sides together. The same statement is true in any number of dimensions:

|u + v| ≤ |u| + |v|

For the example:

|u + v| = √16 + 1 + 16 + 1 = √34 ≈ 5.83the length of the sum (4, 1, 4, 1)|u| + |v| ≈ 2.45 + 5.48 = 7.93the sum of the two lengths

4. The Dot Product as a Weighted Sum

The dot product is useful even when there are no arrows or angles. Suppose that a course grade is 20 percent homework, 30 percent quizzes, and 50 percent tests. Write the weights as the vector w = (0.2, 0.3, 0.5). A student with the scores s = (90, 80, 70) has the course grade

w · s = (0.2)(90) + (0.3)(80) + (0.5)(70)multiply each score by its weightw · s = 18 + 24 + 35the three productsw · s = 77the course grade

An average is also a dot product. The average of four numbers is the dot product of the list of numbers with the vector (¼, ¼, ¼, ¼).

In physics, the work done by a force is F · d, and the power delivered by a force is F · v. In each case the dot product multiplies matching components and adds the results. The weighted sum above uses the same operation.

5. The Standard Unit Vectors

In ℝⁿ there are n vectors that have one component equal to 1 and all of the other components equal to 0. They are called the standard unit vectors, and they are written e₁, e₂, …, eₙ. In ℝ⁴ they are

e₁ = (1, 0, 0, 0) e₂ = (0, 1, 0, 0) e₃ = (0, 0, 1, 0) e₄ = (0, 0, 0, 1)

Each of these vectors has the length 1, and any two different ones are orthogonal. Any vector is a linear combination of them, and the coefficients are the components of the vector.

(3, −1, 4, 2) = 3e₁ − e₂ + 4e₃ + 2e₄

The dot product of a vector with a standard unit vector gives one component. For example, (3, −1, 4, 2) · e₃ = 4.

In physics, the standard unit vectors in three dimensions are usually written î, ĵ, and k̂. A force of (3, −1, 4) newtons is the same as 3î − ĵ + 4k̂ newtons.

Common Mistakes

  • Adding two vectors that have different numbers of components. The sum is not defined.
  • Thinking that a vector in ℝ⁴ needs a fourth direction in space. The number of components only counts how many numbers are in the list.
  • Forgetting a component that is 0 when counting the dimension. The vector (1, 2, 0, −1) is in ℝ⁴, not in ℝ³.
  • Leaving out the square root in the length. The sum v₁² + v₂² + … + vₙ² is the square of the length.
  • Writing the dot product as a vector. The dot product of two vectors is one number.

Summary

TermMeaning
ℝⁿThe set of all vectors with n real components
Dot productu₁v₁ + u₂v₂ + … + uₙvₙ, one number
Length√v · v
OrthogonalThe dot product is 0
Cauchy-Schwarz inequality|u · v| ≤ |u| |v|
Triangle inequality|u + v| ≤ |u| + |v|
Standard unit vectorse₁, …, eₙ, each with one component equal to 1

Practice

Work each problem on paper first. Then open the answer to check your work.

1. For u = (2, 0, −1, 3, 1) and v = (1, 4, 2, −2, 0), calculate u + v and 3u − 2v.

u + v = (3, 4, 1, 1, 1)add the matching components3u − 2v = (6, 0, −3, 9, 3) − (2, 8, 4, −4, 0)multiply u by 3 and v by 23u − 2v = (4, −8, −7, 13, 3)subtract the matching components

2. Calculate the dot product of the two vectors in Problem 1.

dot product = (2)(1) + (0)(4) + (−1)(2) + (3)(−2) + (1)(0)multiply the matching componentsdot product = 2 + 0 − 2 − 6 + 0 = −6add the products

3. Find the length of (1, 1, 1, 1), and the length of the vector in ℝⁿ whose components are all equal to 1.

length = √1 + 1 + 1 + 1 = √4 = 2the vector (1, 1, 1, 1)length = √nfor n components, the sum under the square root is n

4. Find the value of c that makes (1, 2, c, −1) orthogonal to (2, −1, 3, 4).

dot product = 2 − 2 + 3c − 4 = 3c − 4multiply the matching components and add3c − 4 = 0the vectors are perpendicularc = 4/3add 4, then divide by 3

5. Find the angle between (1, 0, 1, 0) and (1, 1, 1, 1).

dot product = 2first length = √2second length = 2cos θ = 2/2√2 = 1/√2divide the dot product by the two lengthsθ = 45°take the inverse cosine

6. A course grade is 25 percent homework, 25 percent labs, and 50 percent tests. A student has the scores 88, 92, and 76. Write the grade as a dot product and calculate it.

The weights are w = (0.25, 0.25, 0.5), and the scores are s = (88, 92, 76).

w · s = (0.25)(88) + (0.25)(92) + (0.5)(76)multiply each score by its weightw · s = 22 + 23 + 38 = 83the course grade

Python Practice

Step 1. Store a vector with many components

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([1, 2, 0, -1]), where np stands for NumPy, the part of Python that works with vectors and matrices. The components go inside the square brackets, with commas between them. A vector can have any number of components.

The instruction len counts the components of a vector.

Python

The second result is 4, so this vector is in ℝ⁴.

Step 2. Add and scale

The + sign adds two vectors, and the * sign multiplies a vector by a number. The code is the same as for vectors with two components.

Python

The result is [4 1 4 1], as in Part 2 of this topic.

Now change the last line so that it prints 2u − v.

Python

Python reports an error if you add two vectors that have different numbers of components. You can test this by deleting one component of v and pressing Run.

Step 3. Calculate a weighted sum

The instruction np.dot calculates a dot product. The code below calculates the course grade from Part 4 of this topic. Python writes a decimal number with a period, as in 0.2.

Python

The result is 77.0.

Now change the weights and the scores to the ones in Practice Problem 6. The weights are 0.25, 0.25, and 0.5, and the scores are 88, 92, and 76.

Python

Step 4. Find a length and an angle

The instruction np.linalg.norm calculates the length of a vector. The code below finds the two lengths and the angle from Part 3 of this topic. The fifth line calculates cos θ. The sixth line finds the angle with np.arccos, the inverse cosine, and changes it from radians to degrees with np.degrees.

Python

The lengths are about 2.45 and 5.48, and the angle is about 94.3 degrees.

Step 5. Make two vectors orthogonal

In the code below, the third component of u is stored under the name c, so the vector is (1, 2, c, −1). Change the value of c so that u is orthogonal to v. This is Practice Problem 4. A fraction can be typed with the / sign, as in 2 / 3.

Python

Quiz

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. The vector (5, 0, −2, 0, 1) belongs to which space?

2. Let u = (2, 0, −1, 3) and v = (1, 4, 2, −2). Calculate 2u − v.

3. Find the length of the vector (1, 2, 2, 4).

4. For which value of c are the vectors (1, c, 2, −1) and (2, 1, 3, 4) perpendicular?

5. A course grade uses the weights w = (0.3, 0.3, 0.4) for homework, quizzes, and tests. A student has the scores s = (80, 90, 70). Find the course grade w · s.

Next: Topic 1.5, The Cross Product