library(geometry)
library(matlib)
u <- c(0.5, 0.5)
v <- c(3, -4)
dot(u,v)
## [1] -0.5
It is the square root of the inner-product of a vector with itself. The dot product of a vector gives the length of a vector squared (Excerpt from Lecture 1).
Length of vector u:
sqrt(0.5^2 + 0.5^2)
## [1] 0.7071068
Length of vector v:
sqrt(3^2 + (-4)^2)
## [1] 5
3*u - 2*v
## [1] -4.5 9.5
Additionaly, we know that the dot product between u and v is the cosine of the angle between them.
acos( sum(u*v) / ( sqrt(sum(u * u)) * sqrt(sum(v * v)) ) )
## [1] 1.712693
solveByElimination3x3 <- function(A, b){
p <- nrow(A)
gaussJ <- cbind(A,b)
gaussJ[1,] <- gaussJ[1,]/gaussJ[1,1]
i <- 2
while (i < p+1) {
j <- i
while (j < p+1) {
gaussJ[j, ] <- gaussJ[j, ] - gaussJ[i-1, ] * gaussJ[j, i-1]
j <- j+1
}
while (gaussJ[i,i] == 0) {
gaussJ <- rbind(gaussJ[-i,],gaussJ[i,])
}
gaussJ[i,] <- gaussJ[i,]/gaussJ[i,i]
i <- i+1
}
for (i in p:2){
for (j in i:2-1) {
gaussJ[j, ] <- gaussJ[j, ] - gaussJ[i, ] * gaussJ[j, i]
}
}
gaussJ
}
A = matrix(c(1,2,-1,1,-1,-2,3,5,4),nrow=3,ncol = 3)
b = c(1,2,6)
solveByElimination3x3(A,b)
## b
## [1,] 1 0 0 -1.5454545
## [2,] 0 1 0 -0.3181818
## [3,] 0 0 1 0.9545455