solving multiple equations with many variables and inequality constraints
<p>I am trying to solve a problem with many variables using scipy and linear programming. I have a set of variables X which are real numbers between 0.5 and 3 and I have to solve the following equations :</p>

<pre><code>346 &lt;= x0*C0 + x1*C1 + x2*C2 +......xN*CN &lt;= 468
25 &lt;= x0*p0 + x1*p1 + x2*p2 +......xN*pN &lt;= 33
12 &lt;= x0*c0 + x1*c1 + x2*c2 +......xN*cN &lt;= 17
22 &lt;= x0*f0 + x1*f1 + x2*f2 +......xN*fN &lt;= 30
</code></pre>

<p>the numbers C0...CN , p0...pN , c0...cN , f0...fN are already given to me. I tried to solve this in the following way:</p>

<pre><code>import numpy as np
from scipy.optimize import linprog
from numpy.linalg import solve
A_ub = np.array([
    [34, 56, 32, 21, 24, 16, 19, 22, 30, 27, 40, 33],
    [2, 3, 2, 1.5, 3, 4, 1, 2, 2.5, 1, 1.2, 1.3],
    [1, 2, 3, 1.2, 2, 3, 0.6, 1, 1, 1.2, 1.1, 0.8],
    [0.5, 2, 2, 1, 3, 4, 1, 1, 1, 0.5, 0.3, 1.2],
    [-34, -56, -32, -21, -24, -16, -19, -22, -30, -27, -40, -33],
    [-2, -3, -2, -1.5, -3, -4, -1, -2, -2.5, -1, -1.2, -1.3],
    [-1, -2, -3, -1.2, -2, -3, -0.6, -1, -1, -1.2, -1.1, -0.8],
    [-0.5, -2, -2, -1, -3, -4, -1, -1, -1, -0.5, -0.3, -1.2]])
b_ub = np.array([468, 33, 17, 30, -346, -25, -12, -22])
c = np.array([34, 56, 32, 21, 24, 16, 19, 22, 30, 27, 40, 33])
res = linprog(c, A_eq=None, b_eq=None, A_ub=A_ub, b_ub=b_ub, bounds=(0.5, 3))
</code></pre>

<p>Explanation for the equations the first row of A_ub is the same as b_ub, as we are trying to maximize the equation as well as make sure it is within the given boundary limits i.e 468 and 346 meaning that I want to get the value as close as possible to the upper limit.</p>

<p>I put <code>[-34, -56, -32, -21, -24, -16, -19, -22, -30, -27, -40, -33]</code> in A_ub and -346 in b_ub with the logic :</p>

<p><code>-346 &gt; -(x0*C0 + x1*C1 + x2*C2 +......xN*CN)</code> which would solve the problem of lower bounds for the equation. I do the same with the rest of them.</p>

<p>But I feel my approach is wrong as I get the answer as <code>0.425</code> for <code>res.fun</code> and <code>nan</code> as the value of <code>res.x</code></p>

<p>The upper bound for x is 3 and the lower bound is 0.5 </p>

<p>How do I define the problem as shown above in order to get a maximum value close to 468 while keeping in mind the upper bounds? How do I define lower bounds using scipy? I am working on linear programming for the first time so I may have missed out on ideas that can help me out.</p>

<p>I am also open to any other solutions.</p>

<p>This system of inequalities is not feasible: there is no solution that satisfies all constraints. You can see that from <code>res</code>:</p>

<pre><code>     fun: 0.42500000000000243
 message: 'Optimization failed. Unable to find a feasible starting point.'
     nit: 28
  status: 2
 success: False
       x: nan
</code></pre>

<p>I believe this is a correct result (I verified this with another LP system).</p>

<p>Note: if you change the bounds to <code>(0,3)</code>, you will get a feasible solution.</p>

python scipy linear-algebra linear-programming