I am looking for a method to solve a system of linear equations in Python.
In particular, I am looking for the smallest integer vector that is larger than all zeros and solves the given equation.
For example, I have the following equation:
and want to solve
.
In this case, the smallest integer vector that solves this equation is
.
However, how can I determine this solution automatically?
If I use scipy.optimize.nnls
, like
A = np.array([[1,-1,0],[0,2,-1],[2,0,-1]])
b = np.array([0,0,0])
nnls(A,b)
the result is (array([ 0., 0., 0.]), 0.0)
.
Which is also correct, but not the desired solution...
Edit: I apologize for being imprecise in certain aspects.
If anyone is interested in the details, the problem comes from the paper
"Static Scheduling of Synchronous Data Flow Programs for Digital Signal Processing", Edward A. Lee and David G. Messerschmitt,
IEEE Transactions on Computers, Vol. C-36, No. 1, pp. 24-35, January, 1987.
Theorem 2 says
For a connected SDF graph with s nodes and topology matrix A and with rank(A)=s-2, we can find a positive integer vector b != 0 such that Ab = 0 where 0 is the zero vector.
Directly after the proof of Theorem 2 they say
It may be desirable to solve for the smallest positive integer vector in the nullspace. To do this, reduce each rational entry in u' so that its numerator and denominator are relatively prime. Euclid's algorithm will work for this.
See Question&Answers more detail:
os