Netflix assignemnt.
u = c(0.5,0.5)
v = c(3,-4)
u%*%v
## [,1]
## [1,] -0.5
#The answer is -0.5
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
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]
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.