sympy / sympy.github.com

SymPy's web page (sympy.org)
https://sympy.org/
188 stars 107 forks source link

question about columnspace() #162

Closed wang-zm18 closed 1 year ago

wang-zm18 commented 3 years ago

I find the wrong case about Matrix.columnspace(), like the folllowing pictures, could you please tell me how to solve it? Thank you in advance! badcase

asmeurer commented 1 year ago

Please post questions on the SymPy mailing list. This is the issue tracker for the SymPy website, and should only be used for issues with the website.

To answer your question, the reason the matrix is not being computed as a rank 2 matrix is because the float values 0.6 and 0.9 are not represented exactly as the rational numbers 6/10 and 9/10, so according to the values those floats actually represent, the matrix has full rank. If you want this calculation to use exactly 0.6 and 0.9, use rational numbers, like

>>> Matrix([[1, 2, 3], [3, 2, 5], [Rational('0.6'), Rational('0.9'), Rational('1.5')]])
Matrix([
[  1,    2,   3],
[  3,    2,   5],
[3/5, 9/10, 3/2]])
>>> Matrix([[1, 2, 3], [3, 2, 5], [Rational('0.6'), Rational('0.9'), Rational('1.5')]]).columnspace()
[Matrix([
[  1],
[  3],
[3/5]]), Matrix([
[   2],
[   2],
[9/10]])]

It is also recommended to avoid creating SymPy objects using NumPy, as NumPy cannot represent the exact rational numbers used by SymPy.