Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #5683 > unrolled thread

Re: Only real data

Started byAndrzej Kozlowski <akoz@mimuw.edu.pl>
First post2011-10-16 11:17 +0000
Last post2011-10-16 11:17 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Only real data Andrzej Kozlowski <akoz@mimuw.edu.pl> - 2011-10-16 11:17 +0000

#5683 — Re: Only real data

FromAndrzej Kozlowski <akoz@mimuw.edu.pl>
Date2011-10-16 11:17 +0000
SubjectRe: Only real data
Message-ID<j7eegp$elc$1@smc.vnet.net>
On 15 Oct 2011, at 12:03, J=F6rg Schr=F6der wrote:

> Hello,
>
>
>
> I have a problem to exclude complex solutions. I tried
>
>
>
> data1={2,3/4,1.3,=E4}
>
>
>
> {2,3/4,1.3,=E4}
>
>
>
> Cases[data1, Except[_Complex]]
>
>
>
> {2,3/4,1.3}
>
>
>
> and got, what I expected. But when I have data like
>
>
>
> {0,0,-I Sqrt[3],I Sqrt[3]}
>
>
>
> The above doesn't work. Is this due to a different Head? Is there an =
easy
> way to filter the non-complex data?
>
>
>
> Thanks in advance
>
>
>
> Greetings
>
>
>
> Joerg
>
>
>
> ################
>
> Dr. J=F6rg Schr=F6der
>
> Bremen, Germany
>


Yes. ,I Sqrt[3] is a product so it has head Times and not Complex. You 
could use:

Select[data, FreeQ[#, Complex] &]

or

Select[data, Element[#, Reals] &]


I consider the second approach better, but note that in more complicated 
cases neither will guarantee that the numbers you have selected are all 
the real numbers in your list.
For example, if

data = {1, I, Cos[2 + I] + I*Sin[2]*Sinh[1]}

both methods will fail to select Cos[2 + I] + I*Sin[2]*Sinh[1]  which is 
a real number since:

ComplexExpand[Cos[2 + I] + I*Sin[2]*Sinh[1]]

cos(2) cosh(1)

Andrzej Kozlowski




[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web