Reputation: 23
If you simplify something like x/x
it results in 1
, but it would be nice if there were a way to make it somehow say 1 iff x is not 0
.
A more serious example: I would like to row reduce a matrix with symbols in one column, and see what values of the symbols make one of the entries zero. Here is my code and the output:
g, h, k = symbols('g h k')
A = Matrix([[1,-4,7,g],[0,3,-5,h],[-2,5,-9,k]])
A.rref()
which results in | Matrix | (((1 0 1/3 0) (0 1 -5/3 0) (0 0 0 1))) | (0 1 3) |
but the 1
in the bottom right entry is really the result of simplifying (2g+h+k)/(2g+h+k)
, which I only know because I did it by hand. I would like it to somehow tell me that this only works if (2g+h+k) is not zero
.
Upvotes: 2
Views: 200
Reputation: 14480
I wrote a function here that can do this sort of thing: https://github.com/sympy/sympy/issues/16861
Unfortunately I haven't gotten round to getting it incorporated in sympy and there are issues to resolve around what exactly it should return and where it could be used within sympy.
In any case with that you can do:
In [5]: eqs = list(A * Matrix([x, y, z, -1]))
In [6]: eqs
Out[6]: [-g + x - 4⋅y + 7⋅z, -h + 3⋅y - 5⋅z, -k - 2⋅x + 5⋅y - 9⋅z]
In [7]: linsolve_cond(eqs, [x, y, z])
Out[7]:
⎧⎧⎛ 4⋅h τ₀ h 5⋅τ₀ ⎞ ⎫
⎪⎨⎜g + ─── - ──, ─ + ────, τ₀⎟ | τ₀ ∊ ℂ⎬ for 6⋅g + 3⋅h + 3⋅k = 0
⎨⎩⎝ 3 3 3 3 ⎠ ⎭
⎪
⎩ ∅ otherwise
Any feedback on how well it works is welcome (ideally on github rather than here).
Upvotes: 2