Finding a solution to a linear system with more unknowns than equations subject (in R)

I have a large system of equations in the software R, with more unknowns than equations. This obviously have a (unlimited) range of solutions. An example of such a system would be

$x_1 + x_2 + x_3 = 5000$

$y_1 + y_2 + y_3 = 2500$

$z_1 + z_2 + z_3 = 7500$

$x_1 + y_1 + z_1 = 10000$

$x_2 + y_2 + z_2 = 3000$

$x_3 + y_3 + x_3 = 2000$

I want to numerically solve the system subject, while minimizing

$\Big|x_1-5000\cdot\frac{10000}{15000}\Big| + \Big|y_1 - 2500\cdot\frac{10000}{15000}\Big|$

This system would be easy to provide a solution intuitively to. However, the real system will have a larger function to minimize as well as more equations.

Do anyone know how to solve such a system in the software R

Let your constraint set be $X$.

Your objective function is of the form of

$$\min |x_1-a_1| + |y_1 - b_1|$$

subject to $x \in X$.

We can convert the optimization problem to $$\min w_1 + w_2$$

subject to $$w_1 \ge x_1-a_1$$ $$w_1 \ge a_1-x_1$$

$$w_2 \ge y_1-b_1$$

$$w_2 \ge b_1 - y_1$$ $$x \in X$$

which is just a linear programming problem.

Remark: For your special problem, set $x_1=a_1$ and $y_1=b_1$ and then you just have to find a feasible solution to minimize the objective function.

• Thanks for the response. I see that my question has been edited to look like I am looking for a solution in the real number. Rather, I am looking for a solution to be programmed in the software R. I have clarified the qeustion now – pkpkPPkafa Aug 15 '18 at 13:39
• why can't you program my solution in R? what difficulty do you face? – Siong Thye Goh Aug 15 '18 at 13:42
• I hope to find a way to numerically solve the problem, and am unsure how to do that in R – pkpkPPkafa Aug 15 '18 at 14:03
• have you look around for packages to call? It is a special class of problem known as linear programming. – Siong Thye Goh Aug 15 '18 at 14:15
• the CRAN optimization task view gives a list of packages that do LP: LP (Linear programming, 90C05): boot, clpAPI, cplexAPI, glpkAPI, limSolve, linprog, lpSolve, lpSolveAPI, quantreg, rcdd, Rcplex, Rglpk, rLindo, Rmosek, Rsymphony – Ben Bolker Aug 20 '18 at 14:20