Vector Spaces: Exercises


1. Orthogonality. Two vectors, a and b are orthogonal if their dot product is equal to zero:

$$a \cdot b = \sum_{i=1}^{N} a_{i}b_{i} = 0$$

In R, we can compute the dot product of two vectors with the %*% operator.

Check whether each pair of vectors in the set {a, b, c} is orthogonal. Note that each vector has been defined for you.


a <- c(1,0,0) b <- c(0,1,0) c <- c(0,0,1) # Compute the dot product of a and b. dot_ab <- a ___ b # Compute the dot product of a and c. dot_ac <- ___ %*% ___ # Compute the dot product of b and c. dot_bc <- ___ # Print the dot products. print(c(dot_ab, dot_ac, dot_bc)) # Compute the dot product of a and b. dot_ab <- a %*% b # Compute the dot product of a and c. dot_ac <- a %*% c # Compute the dot product of b and c. dot_bc <- b %*% c # Print the dot products. print(c(dot_ab, dot_ac, dot_bc)) test_error() test_object("dot_ab", incorrect_msg="Did you use the `%*%` operator?") test_object("dot_ab", incorrect_msg="Did you use the `%*%` operator?") test_object("dot_bc", incorrect_msg="Did you use the `%*%` operator?") success_msg("Excellent work. Is each pair of vectors orthogonal?")
Remember to use the %*% operator to compute the dot product.

Previous Exercise Next Exercise