Solving an undetermined or overdetermined system of equations with constraints

2.3k Views Asked by At

I have a table that looks like this:

enter image description here

I would like to determine the values for each of the different categories in the columns, such that col1*col2*col3 equal what's on the prod column. I've been given constrains on the values each the unknowns can have, and also the table has more entries than shown, and also can have more unknowns.

For example, the following table shows one possible solution:

enter image description here

Hence A=6.77, B=1.93, foo=3.70, ... etc.

Would it be possible to find solutions to this or approximate ones? Or what would I need to make this problem solvable?

Thanks!

1

There are 1 best solutions below

0
On BEST ANSWER

After much research and advice from the comments above, I managed to find a solution using numerical methods in python. Worth to highlight is that I could not use the pseudo-inverse method suggested above (a.k.a. Linear least squares) because the python implementations (scipy.sparse.linalg.lsqr and scipy.optimize.lsq_linear) do not allow for bounds on variables and constrains, so I had to use the more generic scipy.optimize.minimize implementation, which does allow constrains. This can be framed as an optimisation problem of finding the point on the constraint plane which minimizes the quantity ||Ax-b||^2. A good code example of this can be found here: https://stackoverflow.com/questions/31098228/solving-system-using-linalg-with-constraints