Linear Algebra Example

inner <- \(x, y) t(x) %*% y
cosang <- \(x, y) (t(x) %*% y)/(norm(x, "2")*norm(y, "2"))

set.seed(1234)
x1 <- runif(100, -1, 1)/100
x2 <- runif(100, -1, 1)/100
x3 <- 2 * x1 - pi / 1000

inner(x1, x2)
##               [,1]
## [1,] -0.0002300432
inner(x1, x3)
##            [,1]
## [1,] 0.00685714
cosang(x1, x2)
##             [,1]
## [1,] -0.06909636
cosang(x1, x3)
##           [,1]
## [1,] 0.9692014