On Wed, Oct 1, 2008 at 10:50 PM, william ratcliff <[EMAIL PROTECTED]> wrote: > I believe there is a glitch in evalf when complex numbers are involved: > > import sympy > import numpy as N > import scipy.linalg > > pi=N.pi > g=sympy.exp(2*pi*sympy.I) > A=N.matrix([[g,0],[0,g]]) > > scipy.linalg.eig(A) > Traceback (most recent call last): > File "<input>", line 1, in <module> > File "c:\python25\lib\site-packages\scipy\linalg\decomp.py", line 149, in > eig > overwrite_a=overwrite_a) > File "c:\python25\lib\site-packages\sympy\core\basic.py", line 1860, in > __float__ > result = self.evalf() > File "c:\python25\Lib\site-packages\sympy\core\evalf.py", line 950, in > Basic_evalf > prec = dps_to_prec(n) > File "c:\python25\Lib\site-packages\sympy\mpmath\lib.py", line 102, in > dps_to_prec > return max(1, int(round((int(n)+1)*3.3219280948873626))) > File "c:\python25\lib\site-packages\sympy\core\basic.py", line 1864, in > __float__ > raise ValueError("Symbolic value, can't compute") > ValueError: Symbolic value, can't compute > > > I think that the problem is that if there is a complex number that should > result from the evaluation of the exponential, the imaginary portion is left > as a symbol instead of being converted to a complex number. Any ideas? > > > Thanks, > William
This does not look like a bug in evalf. It seems that numpy is calling float(), which fails because g actually has nonzero imaginary part: >>> complex(g) (1-2.4286128663675299e-016j) Is there a good reason for using numpy.pi instead of sympy.pi? With sympy.pi, the complex exponential will simplify symbolically to a real number. Generally, I think using numpy linear algebra functions with sympy elements is unlikely to work well (if at all). You should probably convert all elements to float or complex first. Fredrik --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to sympy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sympy?hl=en -~----------~----~----~----~------~----~------~--~---