DATA 605 - Assignment 1

N. Nedd

2017-09-03


Problem Set One

Problem Set One.

Problem Set One.

Solution

u <- c(0.5,0.5)
v <- c(3,-4)
  1. The dot product

The dot product is as follows:

(0.5 x 3) + (0.5 x -4) = -0.5

The dot() function in R can also be used

dot_prod <- dot(u,v)
dot_prod
## [1] -0.5
  1. Lengths of u and v

Length of a vector:

\(\sqrt(x^2 + y^2)\)

Length of u:

\(\sqrt(0.5^2 + 0.5^2)\) = 0.707

Length of v:

\(\sqrt(3^2 + -4^2)\) = 5

In R:

len_u <- sqrt(sum(u * u))
len_u
## [1] 0.7071068
len_v <- sqrt(sum (v * v))
len_v
## [1] 5
  1. 2u - 3v

2u = (20.5, 20.5) = (1,1) 3v = (33,3-4) = (9,-12)

2u - 3v = (1-9,1–12) = (-8,13)

In R:

comb <- 2*u - 3*v
comb
## [1] -8 13
  1. Angle between u and v

\(cos^-1(dotproduct/product of lengths)\)

$cos^-1((-0.5)/(0.7071068*5)) = 98.1301 degrees

In R:

anglebet <- acos((-0.5)/(0.7071068*5))

#Since answer is in radians need to convert to degrees
angledegrees <- anglebet *180/pi
angledegrees
## [1] 98.1301