I'm using SymPy to perform some operations and stumbled upon this:
If I declare the following matrix and try to get it's 2-norm (largest sing. value):
from sympy import Matrix
Matrix([[4, 1, 0, 0], [1, 4, 1, 0], [0, 1, 4, 1], [0, 0, 1, 4]]) # declare matrix
print(x.norm(2)) # print it's 2-norm
I get the expected result:
sqrt(9*sqrt(5)/2 + 43/2)
But, when I declare a seemingly equivalent matrix and try to get it's 2-norm, I get an error:
from sympy import Matrix
x = Matrix([[7, -13, -3, -1, 0], [-2, 4, 2, 0, 0], [5, -9, -2, 0, 1]]) # declare matrix
print(x.norm(2)) # print it's 2-norm
Error:
Traceback (most recent call last):
File "main.py", line 29, in <module>
print(x.norm(2))
File "venv/lib/python3.9/site-packages/sympy/matrices/matrices.py", line 1984, in norm
return Max(*self.singular_values())
File "venv/lib/python3.9/site-packages/sympy/functions/elementary/miscellaneous.py", line 391, in __new__
args = frozenset(cls._new_args_filter(args))
File "venv/lib/python3.9/site-packages/sympy/functions/elementary/miscellaneous.py", line 564, in _new_args_filter
raise ValueError("The argument '%s' is not comparable." % arg)
ValueError: The argument 'sqrt(121 + 43127/(3*(1723619 + 2*sqrt(199009527)*I/9)**(1/3)) + (1723619 + 2*sqrt(199009527)*I/9)**(1/3))' is not comparable.
I read the source code and learned that is not comparable means that an object can be computed to a real number or already is a real number. I don't see how that matrix can be computed to a real number (it's a matrix).
Can anyone explain why am I getting this error with one matrix but not with the other?
Thanks!