Note: Sheen Zhang helped coordinate a Zoom meeting with Yue Sun, Mikaela Li, and myself. We discussed question 5’s logic and walked through our completed HW versions.

vec.v1 <- c(1,1,0) #create vector V1
vec.v2 <- c(2,3,0) #create vector V2
dim(vec.v1) <- c(3,1) #convert vector into column matrix 
dim(vec.v2) <- c(3,1) #convert vector into column matrix 
v1.norm.1 <- norm(vec.v1, type = "1") #calculate magnitude of matrix V1 (Manhattan norm / L1)
v1.norm.2 <- norm(vec.v1, type = "2") #calculate L2 norm of matrix V1 (Euclidean norm)
v2.norm.1 <- norm(vec.v2, type = "1") #calculate magnitude of matrix V2 (Manhattan norm / L1)
v2.norm.2 <- norm(vec.v2, type = "2")  #calculate L2 norm of matrix V2 (Euclidean norm)

Question 1:

Q: Let u1 <- v1, what is u1? (hint, just write out the vector, this is not a trick question)

vec.u1 <- vec.v1

A: U1 = (1, 1, 0)

Question 2:

Q: Let u2 <- the residual after the orthogonal projection of v2 onto v1 (i.e. u2 <- v2 - projection of v2 onto v1)

vec.v1 <- c(1,1,0)
vec.v2 <- c(2,3,0)
proj.v2.to.v1 <- ((vec.v2 %*% vec.v1) / (vec.v1 %*% vec.v1)) * vec.v1 
vec.u2 <- vec.v2 - proj.v2.to.v1 

A: Vector U2 = (-0.5, 0.5, 0) see below for the step-by-step math
Vector v2 dotted with vector v1 = (5)
Vector v1 dotted with itself = (2)
Those two divided = (2.5)
And when multiplied by v1 again, we get vec.u2 equals (-0.5, 0.5, 0)

Question 3:

Q: Verify that U2 is orthogonal to U1 (i.e. their dot product should be zero)

orth.v1.v2 <- vec.u2 %*% vec.u1
orth.v1.v2
##      [,1]
## [1,]    0

A: Their dot product is indeed zero, so they must be orthogonal to each other

Question 4:

Q: Try to convince yourself that this orthogonal set of vectors U1 and U2also span the same xy plane. Are you convinced? (hint: please say yes!)

A: YES! Because their dot product is zero, then they are both orthogonal and span the same xy plan. The same is true in 3 dimensions if I were to dot product 3 vectors and show they were orthogonal to each other!

Question 5:

Q: Compute the unit vectors U1 & U2

dim(vec.u1) <- c(3,1) #convert vector into column matrix 
dim(vec.u2) <- c(3,1) #convert vector into column matrix 
u1.norm.2 <- norm(vec.u1, type = "2") #calculate L2 norm of matrix u1 (Euclidean norm)
u2.norm.2 <- norm(vec.u2, type = "2")  #calculate L2 norm of matrix u2 (Euclidean norm)
unit.vec.u1 <- vec.u1 /u1.norm.2
unit.vec.u2 <- vec.u2 /u2.norm.2

A: Unit Vector U1 = (0.7071068, 0.7071068, 0) and Unit Vector U2 = (-0.7071068, 0.7071068, 0)