0

I have a problem analogous to this one, i.e. the optimization of four parameters:

a+b+c+1750=T

12=a/T*100

15=b/T*100

37=c/T*100

It can be solved via conversion to matrix formalism then using linear algebra methods:

a + b + c - T = -1750

100 * a - 12 * T = 0

100 * b - 15 * T = 0

100 * c - 37 * T = 0

import numpy as np

a = np.array([[1., 1., 1., -1.],
          [100., 0, 0, -12.],
          [0, 100., 0, -15.],
          [0, 0, 100., -37.]])
b = np.array([-1750., 0, 0, 0])


res, err, _, __ = np.linalg.lstsq(a, b)
# res: [  583.33333333   729.16666667  1798.61111111  4861.11111111]

My real problem needs integer-restricted solutions, i.e. the solutions can only be integers. Is there a restriction that I can place on the np.linalg.lstsq method, or perhaps a different method to solve which will return positive integer-only values for a,b, and c?

I want to be very deliberate in my questioning: This is NOT the same problem as

Solving linear system over integers with numpy

Since that problem was based all on integers, ie the equations and solutions contain only integers. The present question is different. From some experimental data, I get decimal values, since the measurement is imperfect. So my equations have decimals. Since the system in reality is quantized (coming from number of molecules) the solutions can only be integers. So there is some integer solution which best fits the data. Even though the problem can be solved analytically, the solution in reality has integer- only solutions so must be fitted via some optimization procedure.

So I reiterate the question: does someone know of a method to find the best solution to a system of equations where the solutions can only be zero or postive integers?

notAI
  • 111
  • 1
  • 10
  • What do you mean by "optimized" and "integer solution"? Your equation system has exactly one solution and it is not an integer solution. [But this was explained to you in your previous question.](https://stackoverflow.com/a/50725560/8881141) – Mr. T Jun 09 '18 at 07:29
  • Youre right this example obviously has exactly one solution. Obviously it can be solved by analytical methods. But the real world solution can only have integer-valued answers, so does not have an analytical solution so needs to be approximated using some sort of fitting method. So if i restrict this to integer only solutions, I would like to find the best fit with this restriction. – notAI Jun 09 '18 at 14:07

0 Answers0