1. Problem Set 1

Netflix assignemnt.

  1. Calculate the dot product u.v where u = [0.5; 0.5] and v = [3;-4]
u = c(0.5,0.5)
v = c(3,-4)
u%*%v
##      [,1]
## [1,] -0.5
#The answer is -0.5
  1. What are the lengths of u and v.
v = c(3,-4)
sqrt(v%*%v)
##      [,1]
## [1,]    5
#The answer is 5.0 for the length of v

u = c(0.5,0.5)
sqrt(u%*%u)
##           [,1]
## [1,] 0.7071068
#The answer is 0.707 for the length of u
  1. What is the linear combination of 3u-2v?
u = c(0.5,0.5)
v = c(3,-4)
3*u - 2*v
## [1] -4.5  9.5
#the answer is vector [-4.5 9.5]
  1. What is the angle between u and v

cos(theta) = u.v / ||u||*||v||

dot = u%*%v
magu = sqrt(u%*%u)
magv = sqrt(v%*%v)
costheta = dot / (magu * magv)

acos(costheta)
##          [,1]
## [1,] 1.712693
#the angle is 1.713 radians

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.