# Dot product of vectors in 1st method
library("geometry")
u <- c(0.5,0.5)
v <- c(3,-4)
dotproduct <- dot(u,v,d = NULL)
print(dotproduct)
## [1] -0.5
### Dotprodcut of vectors in 2nd method
u <- matrix(c(0.5,0.5), ncol=1)
v <- matrix(c(3,-4), ncol=1)
u<- c(0.5,0.5)
v<- c(3,-4)
dot_prod <- u %*% v
dot_prod
## [,1]
## [1,] -0.5
# Finding length of the vectors
len_u <- sqrt(sum(u*u))
len_v <- sqrt(sum(v*v))
print(len_u)
## [1] 0.7071068
print(len_v)
## [1] 5
# Linearcombination of 3u-2v
u <- c(0.5,0.5)
v <- c(3,-4)
lin_comb <- 3*u - 2*v
lin_comb
## [1] -4.5 9.5
# Angle between the vectors
angle_uv <- acos(dotproduct/(len_u*len_v))
angle_uv
## [1] 1.712693
angle_in_degrees <- angle_uv*180/pi
angle_in_degrees
## [1] 98.1301
# Solving matrix
m <- matrix(c(1,2,-1,1,-1,-2,3,5,4),nrow = 3, ncol = 3, byrow = FALSE)
m
## [,1] [,2] [,3]
## [1,] 1 1 3
## [2,] 2 -1 5
## [3,] -1 -2 4
b <- matrix(c(1,2,6), ncol = 1)
b
## [,1]
## [1,] 1
## [2,] 2
## [3,] 6
result <- solve(m,b)
round(result, digits = 2)
## [,1]
## [1,] -1.55
## [2,] -0.32
## [3,] 0.95
You can also embed plots, for example: