0

I'm trying to solve the following system of equations:

0.5 * x1 + 0.75 * x2 + 0.25 * x3 = 0.25
x1 + x2 + x3 = 1

I first randomly select $x3$ from a uniform distribution. Then I update my system of equations to solve for the remaining x1 and x2. I want to make sure that both x1 and x2 are between 0 and 1. Therefore, I set up the following system of equations to feed into lp from lpSolve. Note that I need to simultaneously maximize and minimize the objective function. But I am not sure how to do that with lp.

########
# max x1 + x2 subject to the following constraints (I want to minimize this simultaneously, but not sure how to specify this in `lp`)
# 0.5*x1 + 0.75*x2 = 1 - 0.25*x3
# x1 + x2 = 1 - x3
# x1 + 0 * x2 > 0
# 0*x1 + x2 > 0
# x1 + 0 * x2 < 1
# 0*x1 + x2 < 1

libary(lpSolve)
set.seed(3)
x3 <- runif(1, 0.01, 0.99)
f.obj <- c(1, 1)
f.con <- matrix(c(2/4, 3/4, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1), nrow = 6, byrow = TRUE)
f.dir <- c("=", "=", ">", ">", "<", "<")
f.rhs <- c(0.25 - 1/4 * x3, 1 - x3, 0, 0, 1, 1)
lp ("min", f.obj, f.con, f.dir, f.rhs)$solution
Adrian
  • 9,229
  • 24
  • 74
  • 132
  • Conditional on the value of `x3`, the system of linear equations has a unique solution for `x1` and `x2`, how would their sum still be maximized/minimized? – Joris C. Aug 20 '19 at 16:17
  • The unique solution for `x1` and `x2` may not be constrained between 0 and 1. So I set up additional 4 constraints `x1 + 0 * x2 > 0, 0*x1 + x2 > 0, x1 + 0 * x2 < 1, 0*x1 + x2 < 1`. I tried using `matlib`'s `Solve` function, but they do not let me specify constraints that use the operators `<` or `>`. Only `=` is allowed. That's why I'm using `lp` from `lpSolve` instead. – Adrian Aug 20 '19 at 16:24
  • Here is my code for using `matlib`'s `Solve`. Note that the solutions are not between 0 and 1. `library(matlib); set.seed(3); x3 <- runif(1, 0.01, 0.99); A <- matrix(c(1, 2/4, 1, 3/4), 2, 2); b <- c(1 - x3, 0.25 - 1/4 * x3); Solve(A, b); #x1 = -0.34936139 #x2 = 1.1746807` – Adrian Aug 20 '19 at 16:26
  • If you would insert other values for `x1` and `x2`, the `=` equations in your linear system are no longer satisfied, because the solution you obtain is the *unique* solution for `x1` and `x2` given the linear system. – Joris C. Aug 20 '19 at 16:35

0 Answers0