library('geometry')## Loading required package: magic
## Warning: package 'magic' was built under R version 3.4.3
## Loading required package: abind
u <- c(0.5, 0.5)
v <- c(3,-4)
dotpro <- u%*%v
dotpro## [,1]
## [1,] -0.5
paste0("dot product is: ", dotpro)## [1] "dot product is: -0.5"
Length of vector is usually given by formula v = β(x^2 + y^2)) Calculated manually using above formula U = sqrt [ (0.5)^2 + (0.5)^2] = sqrt(0.5) = 0.71 V = sqrt [ (3)^2 + (-4)^2 ] = sqrt (25) = 5
length(u)## [1] 2
length(v)## [1] 2
lin_com <- 3*u - 2*v
paste0("linear combination is", lin_com)## [1] "linear combination is-4.5" "linear combination is9.5"
To calculate angle we have to use formula Cos πͺ = uβ v/ βuββ βvβ i.e dot product (uv) / length of u * length of v
angle <- acos(dot(u,v) / (0.71*5))
angle1 <- angle * 180/pi #to convert radian into degrees
angle1## [1] 98.09675
You can use R-markdown to submit your responses to this problem set. If you decide to do it in paper, then please either scan it or take a picture using a smartphone and attach that picture. Please make sure that the picture is legible before submitting.
Please test it with the system below and it should produce a solution x = [β1.55, β0.32, 0.95]
Solving using the pivot and multiply (1) Start with row 1 of the co-efficient matrix (2) Pivot: The first non-zero element in the row being evaluated (3) Multiplier: The element being eliminated divided by the Pivot (4) Subtract Multiplier times row n from row n+1 (5) Advance to the next row and repeat
solve_equation <- function(a, b) {
a <- cbind(a, b)
pivot <- a[1, 1]
multi <- a[2, 1]/pivot
row1 <- a[1,]
row2 <- a[2,]
a[2,] <- row2 - row1 * multi
pivot <- a[1, 1]
multi <- a[3, 1]/pivot
row1 <- a[1,]
row3 <- a[3,]
a[3,] <- row3 - row1 * multi
pivot <- a[2, 2]
multi <- a[3, 2]/pivot
row2 <- a[2,]
row3 <- a[3,]
a[3,] <- row3 - row2 * multi
x3 <- a[3, 4] / a[3, 3]
x2 <- (a[2, 4] - a[2, 3] * x3) / a[2, 2]
x1 <- (a[1, 4] - a[1, 3] * x3 - a[1, 2] * x2) / a[1, 1]
value <- c(x1, x2, x3)
return(round(value, 2))
}
matrixA <- c(1, 2, -1, 1, -1, -2, 3, 5, 4)
constantB <- c(1, 2, 6)
FinalValues <- matrix(matrixA, 3, 3)
solve_equation(FinalValues, constantB)## b b b
## -1.55 -0.32 0.95