`$\mathbb{R}^{n \times n}$`
"""
-from sage.all import *
-
def unit_eigenvectors(A):
"""
Return the unit eigenvectors of a symmetric positive-definite matrix.
ValueError: The base ring of ``A`` must be a field.
"""
+ from sage.symbolic.ring import SR
if not A.base_ring().is_exact() and not A.base_ring() is SR:
msg = 'The base ring of ``A`` must be either exact or symbolic.'
all_evs = unit_eigenvectors(A)
evs = [ (val,vec) for (val,vec) in all_evs if not val == 0 ]
+ from sage.matrix.constructor import matrix
d = ( val.sqrt() for (val,vec) in evs )
- root_D = diagonal_matrix(d).change_ring(A.base_ring())
-
- Q = matrix(A.base_ring(), ( vec for (val,vec) in evs )).transpose()
+ root_D = matrix.diagonal(d).change_ring(A.base_ring())
+ Q = matrix.column(A.base_ring(), ( vec for (val,vec) in evs ))
return Q*root_D*Q.transpose()
rank_A = 0
if rank is None:
# Choose one randomly
+ from sage.rings.all import ZZ
rank_A = ZZ.random_element(n+1)
elif (rank < 0) or (rank > n):
# The rank of ``A`` can be at most ``n``.
raise ValueError('You must have accept_zero=True when V is trivial')
# Loop until we find a suitable "A" that will then be returned.
+ from sage.matrix.constructor import matrix
while True:
# Begin with the zero matrix, and add projectors to it if we
# have any.