def _pos_dependent(matrix, vector):
"""Check if vector can be written as a positive linear combination of
the columns of matrix.
Return the coeffients if possible, None otherwise."""
if len(matrix) > 0:
coeffs = Matrix(list(map(lambda i: Symbol("x" + str(i)), range(len(matrix)))))
sols = solve(Matrix(matrix).T * coeffs - Matrix(vector), coeffs, dict = True, particular = True)
for sol in sols:
if all([sol[s] >= 0 for s in sol]):
return [sol[s] if s in sol else 0 for s in coeffs]
return None
评论列表
文章目录