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: [mg92003] Re: how to test where a list contains constant(s) or not
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Tue, 16 Sep 2008 19:25:52 -0400 (EDT)

On 9/15/08 at 3:41 AM, sh_liuhuashan at 163.com (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 ];
>]
>

Your function looks overly complex. If I understand correctly
what you want to do then

constantQ[x_List] := Or @@ (NumericQ /@ x)

should work. Using this on your test cases gives

In[58]:= constantQ@{a, b, c, Pi}
constantQ@{a, b, c, 0.0001}
constantQ@{a, b, c, 2 + Pi I}
constantQ@{a, b, c}


Out[58]= True

Out[59]= True

Out[60]= True

Out[61]= False


  • Prev by Date: Re: how to test where a list contains constant(s) or not
  • Next by Date: Re: Apparent error integrating product of DiracDelta's
  • 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