Re: Checking for non-complex numerics
- To: mathgroup at smc.vnet.net
- Subject: [mg21028] Re: [mg20983] Checking for non-complex numerics
- From: Andrzej Kozlowski <andrzej at platon.c.u-tokyo.ac.jp>
- Date: Thu, 2 Dec 1999 21:41:39 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
A further reflection. Numerical computations in Mathematica often produce seemingly complex numbers with very tiny imaginary parts (e.g. 1+0. I) when actually the answer is real. These cannot be identified as complex by my NonComplexFunction: In[10]:= Element[ComplexExpand[#], Reals] && NumericQ[#] &[1 + 0. I] Out[10]= False In such cases one could use numerical checking: In[12]:= Element[Chop[N[#]], Reals]&&NumericQ[#] & [1 + 0. I] Out[12]= True On the other hand, it maybe that you actually get complex numbers with very small imaginary parts which you do not wish to count as reals. In that case the fist code may be better. Here is another example: v = 1 + 10^(-15)*I; In[2]:= Element[Chop[N[#]], Reals] && NumericQ[#] & [v] Out[2]= True In[3]:= Element[ComplexExpand[#], Reals] && NumericQ[#] &[v] Out[3]= False Which is better really depends on what you are going to use this for. > From: "Mark R. Diamond" <markd at psy.uwa.edu.au> To: mathgroup at smc.vnet.net > Reply-To: markd at psy.uwa.edu.au > Date: Thu, 2 Dec 99 11:13:01 +0800 > To: Andrzej Kozlowski <andrzej at platon.c.u-tokyo.ac.jp> > Subject: [mg21028] Re: [mg20983] Checking for non-complex numerics > > Many thanks; the funciton you wrote will provide me with just what I > need. Even better, I was not aware of Element or ComplexExpand so > those will add to my repertoire! > > Mark Diamond