Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

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

Search the Archive

Re: how to test where a list contains constant(s) or not

  • To: mathgroup at smc.vnet.net
  • Subject: [mg91996] Re: how to test where a list contains constant(s) or not
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Tue, 16 Sep 2008 19:24:35 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <gal3iu$e0a$1@smc.vnet.net>

Aya wrote:

> case1: { a, b, c, Pi }   gives true because of Pi
> case2: { a, b, c, 0.0001} gives true because of 0.0001
> case3: { a, b, c,  2 + Pi I } gives ture becase of 2 + Pi I
> case4: { a, b, c} gives false
> 
> is this function right ?
> 
> ComplexQ[z_] := NumericQ[ z ] || ( NumericQ[ z ] && SameQ[ Head[ z ],
> Complex] )
> IsConstantsIn[ lstList_ ] :=
> 		Module[ { intLength },
> 			intLength = Length@Select[ lstList, ComplexQ[ # ]& ];
> 			If[ intLength > 0, Return[ True ], Return[ False ] ];
> 			Return[ False ];
> 			]
> 

As written above, the predicate ComplexQ is equivalent to NumericQ. So 
you could write your function directly as follows:


In[1]:= IsConstantsIn[lstList_] :=

  If[Length@Select[lstList, NumericQ[#] &] > 0, True, False]

(* Now, is this what you are looking for? I do no know. You should 
describe precisely what you intent to do. *)

case = {{a, b, c, Pi}, {a, b, c, 0.0001}, {a, b, c, 2 + Pi I}, {a, b,
     c}};

IsConstantsIn /@ case

Out[3]= {True, True, True, False}

In[4]:= NumericQ /@ case[[4]]

Out[4]= {False, False, False}

In[5]:= Head /@ case[[4]]

Out[5]= {Symbol, Symbol, Symbol}


Regards,
-- Jean-Marc


  • Prev by Date: Problem in PL spectrum analysis
  • Next by Date: Re: Problem with replacement rules
  • Previous by thread: Re: how to test where a list contains constant(s) or not
  • Next by thread: Re: how to test where a list contains constant(s) or not