u<-c(0.5,0.5)
v<-c(3,-4)
d<-u%*%v
The dot product u.v is -0.5
u<-c(0.5,0.5)
len_u<-sqrt(u%*%u)
v<-c(3,-4)
len_v<-sqrt(v%*%v)
The length of u is 0.7071068 and the length of v is 5
u<-c(0.5,0.5)
v<-c(3,-4)
lin_comb<-3*u - 2*v
The linear combination is -4.4 and 9.5
ang<-d / (len_u*len_v)
acos(ang)
## [,1]
## [1,] 1.712693
The angle between u and v is 1.712693
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.
library(matlab)
##
## Attaching package: 'matlab'
## The following object is masked from 'package:stats':
##
## reshape
## The following objects are masked from 'package:utils':
##
## find, fix
## The following object is masked from 'package:base':
##
## sum
equ1<- matrix(c(1, -1, 1,2, 3,-5,1,2,3), 3, 3, byrow=TRUE)
colnames(equ1) <- paste0('x', 1:3)
equ2 <- c(3, 2, 6)
equ1
## x1 x2 x3
## [1,] 1 -1 1
## [2,] 2 3 -5
## [3,] 1 2 3
equ2
## [1] 3 2 6
solve(equ1, equ2)
## x1 x2 x3
## 2.5483871 0.4193548 0.8709677