[Matplotlib-users] ValueError: math domain error From: Nils Wagner - 2005-06-22 13:20 Attachments: cdiff.py ```Hi all, Why do I get a math domain error if I import scipy before pylab in cdiff.py (see attachment) ? numerix Numeric 24.0b2 Traceback (most recent call last): File "cdiff.py", line 28, in ? e1=abs((f(z+h)-f(z))/h-fd(z))/abs(fd(z)) File "cdiff.py", line 6, in f return exp(z)/sqrt(sin(z)**3+cos(z)**3) ValueError: math domain error /home/nwagner> vi cdiff.py /home/nwagner> /usr/bin/python cdiff.py numerix Numeric 24.0b2 Traceback (most recent call last): File "cdiff.py", line 30, in ? e1=abs((f(z+h)-f(z))/h-fd(z))/abs(fd(z)) File "cdiff.py", line 6, in f return exp(z)/sqrt(sin(z)**3+cos(z)**3) ValueError: math domain error Nils ```
 Re: [Matplotlib-users] ValueError: math domain error From: John Hunter - 2005-06-22 13:34 ```>>>>> "Nils" == Nils Wagner writes: Nils> Hi all, Why do I get a math domain error if I import scipy Nils> before pylab in cdiff.py (see attachment) ? Hi Nils, It helps to try and reduce your error to a minimal example that exposes the bug. That will save my time and help you find the real cause of the bug. If you had done this, you would have seen that the problem is in the Numeric call to sqrt of a negative number, and does not involve matplotlib or scipy from Numeric import sqrt, sin, cos z = 2.5 print 'arg is negative', sin(z)**3+cos(z)**3 print 'this will fail', sqrt(sin(z)**3+cos(z)**3) numarray would return nan. JDH ```