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


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

Only real data

Started byJörg Schröder <HB-Kowalczyk-Schroeders@t-online.de>
First post2011-10-15 10:05 +0000
Last post2011-10-16 11:16 +0000
Articles 3 — 3 participants

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


Contents

  Only real data Jörg Schröder <HB-Kowalczyk-Schroeders@t-online.de> - 2011-10-15 10:05 +0000
    Re: Only real data dimitris <dimmechan@yahoo.com> - 2011-10-16 11:15 +0000
    Re: Only real data "Dr. Wolfgang Hintze" <weh@snafu.de> - 2011-10-16 11:16 +0000

#5659 — Only real data

FromJörg Schröder <HB-Kowalczyk-Schroeders@t-online.de>
Date2011-10-15 10:05 +0000
SubjectOnly real data
Message-ID<j7blu7$34t$1@smc.vnet.net>
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

[toc] | [next] | [standalone]


#5678

Fromdimitris <dimmechan@yahoo.com>
Date2011-10-16 11:15 +0000
Message-ID<j7eec0$ekc$1@smc.vnet.net>
In reply to#5659
Hi.

Say:

lst = {2, 3/4, Pi, E, 3 + 4*I, Sqrt[-I], Sqrt[-1], 5 + Pi*I,
Sin[Pi*I], Exp[I*Pi], I^I, I*Log[I], BesselJ[0, 2]};

Then one way to proceed is the following:

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

{2, 3/4, Pi, E, -1, I^I, -(Pi/2), BesselJ[0, 2]}


Best Regards




[toc] | [prev] | [next] | [standalone]


#5680

From"Dr. Wolfgang Hintze" <weh@snafu.de>
Date2011-10-16 11:16 +0000
Message-ID<j7eedt$ekh$1@smc.vnet.net>
In reply to#5659
You can select the reals easily using Im[]==0

x = {1, 1.5, I, I + 1, I*Sqrt[2], I*Sqrt[2.]}
    {1, 1.5, I, 1 + I, I*Sqrt[2], 1.4142135623730951*I}

Select[x, Im[#1] == 0 & ]
    {1, 1.5}


Turning to your attempt:
You are right. Using Head[] or FullForm[] reveals that the Head of 
I*Sqrt[2] is not Complex but is is Times.
To see this here are some examples:
x = {1, 1.5, I, I + 1, I*Sqrt[2], I*Sqrt[2.]}
    {1, 1.5, I, 1 + I, I*Sqrt[2], 1.4142135623730951*I}

Head /@ x
    {Integer, Real, Complex, Complex, Times, Complex}

Cases[x, _Complex]
    {I, 1 + I, 1.4142135623730951*I}

Cases[x, Except[_Complex]]
    {1, 1.5, I*Sqrt[2]}

Cases[x, _Times]
    {I*Sqrt[2]}

--- Wolfgang


"Jörg Schröder" <HB-Kowalczyk-Schroeders@t-online.de> schrieb im 
Newsbeitrag news:j7blu7$34t$1@smc.vnet.net...
> 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
> 

[toc] | [prev] | [standalone]


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


csiph-web