MSDS Spring 2018

DATA 605 Fundamentals of Computational Mathematics

Jiadi Li

HW #1 - Problem Set 1:Vectors

  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)
cat("The dot product of u and v is ",sum(U*V),".")
## The dot product of u and v is  -0.5 .
  1. What are the lengths of u and v?
u_len <- sqrt(sum(U*U))
v_len <- sqrt(sum(V*V))
cat("The length of vector u is ",u_len,"; the length of vector v is ",v_len,".")
## The length of vector u is  0.7071068 ; the length of vector v is  5 .
  1. What is the linear combination: 3u-2v?
result <- 3*U-2*V
cat("3u - 2v = [",result[1],";",result[2],"].")
## 3u - 2v = [ -4.5 ; 9.5 ].
  1. What is the angle between u and v?
uv_angle <- acos(sum(U*V)/(u_len*v_len)) #Law of Cosine
cat("The angle between vectors u and v is ",uv_angle,".")
## The angle between vectors u and v is  1.712693 .