0
votes

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.

1
You could just drop the absolute values and solve it -- it's a system of two equations with two unknowns. - josliber
@josilber actually your suggestion will only give part of the solutions. If janak needs all solutions then he needs also to solve the ones with a minus sign instead of the absolute value. That's 4 sets of two equations with two unknowns - RockScience
@RockScience. I just wanted to point out this, then I saw your comments. You are right I need all the solution of this equations. - Janak

1 Answers

1
votes

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)