Suppose I have the following equations:
|2x+4y-9|=54
|5x-6y+14|=21
How do I solve these equations for x and y. I would like to solve these equations using R.
Suppose I have the following equations:
|2x+4y-9|=54
|5x-6y+14|=21
How do I solve these equations for x and y. I would like to solve these equations using R.
How about something like this:
A <- matrix(c(2,4,5,-6),nrow=2,byrow=TRUE)
b <- c(54,21)
ex <- c(-9,14)
z1 <- solve(A,b-ex)
z2 <- solve(A,-b-ex)
z3 <- solve(A,c(-b[1],b[2])-ex)
z4 <- solve(A,c(b[1],-b[2])-ex)
z1;z2;z3;z4
Check if results are what is required
A%*%z1+ex
[,1]
[1,] 54
[2,] 21
and so forth for the remaining variants
A%*%z2+ex
A%*%z3+ex
A%*%z4+ex
Addendum:
A more efficient way of solving the system of equations is
B <- cbind(b,-b,c(-b[1],b[2]),c(b[1],-b[2]) )
solve(A,B-ex)