requires geometry
library(geometry)
u=c(0.5,0.5)
v=c(3,−4)
dot(u,v)
## [1] -0.5
u=c(0.5,0.5)
sqrt(dot(u,u))
## [1] 0.7071068
v=c(3,-4)
sqrt(dot(v,v))
## [1] 5
(3*u)-(2*v)
## [1] -4.5 9.5
requires Morpho
library(Morpho)
angle.calc(u,v)
## [1] 1.712693
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.
Set up a system of equations with 3 variables and 3 constraints and solve for x. Please write a function in R that will take two variables (matrix A & constraint vector b) and solve using elimination. Your function should produce the right answer for the system of equations for any 3-variable, 3-equation system. You don’t have to worry about degenerate cases and can safely assume that the function will only be tested with a system of equations that has a solution. Please note that you do have to worry about zero pivots, though. Please note that you should not use the built-in function solve to solve this system or use matrix inverses. The approach that you should employ is to construct an Upper Triangular Matrix and then back-substitute to get the solution. Alternatively, you can augment the matrix A with vector b and jointly apply the Gauss Jordan elimination procedure.
x <- function(A, b) {
A <- cbind(A, b)
mltpr <- A[2,1]/A[1,1]*(A[1,])
A[2,] = A[2,]-mltpr
mltpr <- (A[3,1]/A[1,1]*(A[1,]))
A[3,] = A[3,]-mltpr
mltpr <- (A[3,2]/A[2,2]*(A[2,]))
A[3,] = A[3,]-mltpr
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]
return(c(x1, x2, x3))
}
A <- matrix(c(1, 2, -1, 1, -1, -2, 3, 5, 4), 3, 3)
b <- matrix(c(1, 2, 6), 3, 1)
x(A, b)
## [1] -1.5454545 -0.3181818 0.9545455