Thank you for the suggestions, David and William. The following code seems to fix the eigenvalue bug for real matrices, though the precision is limited by Numeric.
import Numeric from LinearAlgebra import eigenvalues from Precision import Float def numeric_eigenvalues(A): """ Returns the eigenvalues of a real matrix A using numeric. EXAMPLES: sage: MS = MatrixSpace(RR,4,4) sage: A = MS([[1,2,3,4],[4,3,2,1],[4,5,6,7],[5,4,3,5]]) sage: numeric_eigenvalues(A) [14.824130101585023, -0.69618928224330556, 8.3349071452372122e-16, 0.87205918065828203] """ import Numeric #from LinearAlgebra import eigenvalues #from Numeric.Numeric import array,eigenvalues,reshape n = len(A[0]) AN = Numeric.array([A[i].list() for i in range(n)],Float) lambdas = eigenvalues(AN) return list(lambdas) David Joyner wrote: > Hello all: > > I'm trying to import Numeric to fix the eigenvalues bug for real and complex > matrices. The following function should do it but it has problems I > think with the > eigenvalues line. Am I importing something wrong? > > - David Joyner > > ++++++++++++++++++++++ > > def numeric_eigenvalues(A): > """ > Returns the eigenvalues of a real matrix A using numeric. > > EXAMPLES: > sage: MS = MatrixSpace(RR,4,4) > sage: A = MS([[1,2,3,4],[4,3,2,1],[4,5,6,7],[5,4,3,5]]) > sage: numeric_eigenvalues(A) > > """ > import Numeric > #from Numeric.Numeric import array,eigenvalues,reshape > n = len(A[0]) > AN = Numeric.reshape(A.list(),(n,n)) > lambdas = Numeric.eigenvalues(AN) > return lambdas > > > sage: MS = MatrixSpace(RR,4,4) > sage: A = MS([[1,2,3,4],[4,3,2,1],[4,5,6,7],[5,4,3,5]]) > sage: numeric_eigenvalues(A) > --------------------------------------------------------------------------- > <type 'exceptions.AttributeError'> Traceback (most recent call last) > > /home/wdj/sagefiles/sage-1.4.1.2/<ipython console> in <module>() > > /home/wdj/sagefiles/sage-1.4.1.2/<ipython console> in numeric_eigenvalues(A) > > <type 'exceptions.AttributeError'>: 'module' object has no attribute > 'eigenvalues' > > > > > --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://sage.math.washington.edu/sage/ and http://sage.scipy.org/sage/ -~----------~----~----~----~------~----~------~--~---