MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Only real data

  • To: mathgroup at smc.vnet.net
  • Subject: [mg122136] Re: Only real data
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Sun, 16 Oct 2011 07:06:14 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com

On 10/15/11 at 6:03 AM, HB-Kowalczyk-Schroeders at t-online.de (J=C3=B6rg
Schr=C3=B6der) wrote:

>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?

Yes, the issue is

In[21]:= Head[I Sqrt[3]]

Out[21]= Times

You can filter out anything with a complex value with FreeQ as follows:

In[22]:= Cases[{0, 0, -I Sqrt[3], I Sqrt[3]}, _?(FreeQ[#,
_Complex] &)]

Out[22]= {0,0}

=46reeQ[expr, pattern] returns True when any subexpression of expr
matches pattern




  • Prev by Date: Re: How to create this kind of list
  • Next by Date: Re: How to create this kind of list
  • Previous by thread: Re: Only real data
  • Next by thread: Re: Only real data