Problem Set 1

1.1

u <- c(0.5 , 0.5 )
v <- c(3,-4)
u%*%v
##      [,1]
## [1,] -0.5

1.2

l_u <-sqrt(sum(u^2))
l_u
## [1] 0.7071068
l_v <-sqrt(sum(v^2))
l_v
## [1] 5

1.3

(3*u) - (2*v)
## [1] -4.5  9.5

1.4

angle =acos(sum(u*v) / (l_u * l_v))
as.numeric(angle)* 180/pi
## [1] 98.1301

Problem Set 2

2.1

find_x <- function(m, v){
  t <- cbind(m,v)
  
  p1 <- t[2,1]/t[1,1]
  t[2,] <- t[2,] - (t[1,]*p1)
  p2 <- t[3,1]/t[1,1]
  t[3,] <- t[3,] - (t[1,]*p2)
  p3 <- t[3,2]/t[2,2]
  t[3,] <- t[3,] - (t[2,]*p3)
  
  
  x3 <- t[3,4] / t[3,3]
  x2 <- (t[2,4] - (t[2,3]*x3)) / t[2,2]
  x1 <- (t[1,4] - (t[1,3]*x3) - (t[1,2]*x2)) / t[1,1]
  
  
  x <- matrix(c(x1, x2, x3), nrow = 3)

  return(x)
  
} 

#test function  
m <- matrix(c(1, 2, -1, 1, -1, -2, 3, 5, 4), ncol=3, nrow = 3)
v <- c(1, 2, 6)


find_x(m,v)
##            [,1]
## [1,] -1.5454545
## [2,] -0.3181818
## [3,]  0.9545455