We know the Dot product is computed like this:

\[u \cdot v=(u_1×v_1)+(u_2×v_2)+...+(u_n×v_n)= \sum_{i=1}^{n}=u_i \cdot v_i\]

Problem Set 1

#1
library(pracma)
## Warning: package 'pracma' was built under R version 3.4.4
u<-c(0.5,0.5)
v<-c(3,-4)
dot(u,v)
## [1] -0.5
#2
sqrt(sum(u^2)) # length of vector u
## [1] 0.7071068
sqrt(sum(v^2)) # length of vector v
## [1] 5
#3
3*u-2*v
## [1] -4.5  9.5
#4
theta <- acos( sum(u*v) / ( sqrt(sum(u * u)) * sqrt(sum(v * v)) ) )
theta #We know we need to get theta
## [1] 1.712693

Problem Set 2

A = matrix(c(1,1,3,2,-1,5,-1,-2,4),
         nrow=3, ncol=3, byrow=TRUE)

B = matrix(c(1,2,6),
          nrow=3, ncol=1, byrow=TRUE)

p <- nrow(A)
(U.pls <- cbind(A,B))
##      [,1] [,2] [,3] [,4]
## [1,]    1    1    3    1
## [2,]    2   -1    5    2
## [3,]   -1   -2    4    6
U.pls[1,] <- U.pls[1,]/U.pls[1,1]

i <- 2
while (i < p+1) {
 j <- i
 while (j < p+1) {
  U.pls[j, ] <- U.pls[j, ] - U.pls[i-1, ] * U.pls[j, i-1]
  j <- j+1
 }
 while (U.pls[i,i] == 0) {
  U.pls <- rbind(U.pls[-i,],U.pls[i,])
 }
 U.pls[i,] <- U.pls[i,]/U.pls[i,i]
 i <- i+1
}
for (i in p:2){
 for (j in i:2-1) {
  U.pls[j, ] <- U.pls[j, ] - U.pls[i, ] * U.pls[j, i]
 }
}
U.pls
##      [,1] [,2] [,3]       [,4]
## [1,]    1    0    0 -1.5454545
## [2,]    0    1    0 -0.3181818
## [3,]    0    0    1  0.9545455
U.pls[,4] #solutions
## [1] -1.5454545 -0.3181818  0.9545455
solve(A,B) #Indeed, the function above matches with the results in solve function.
##            [,1]
## [1,] -1.5454545
## [2,] -0.3181818
## [3,]  0.9545455