MathGroup Archive 2008

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

Search the Archive

Using 'IF' function on 'Lists' in Mathematica 6.01

  • To: mathgroup at smc.vnet.net
  • Subject: [mg85035] Using 'IF' function on 'Lists' in Mathematica 6.01
  • From: "Lea Rebanks" <lrebanks at netvigator.com>
  • Date: Thu, 24 Jan 2008 04:50:49 -0500 (EST)

Dear All,

I trying to Use the 'IF' function on a 'List' - 'data' below.

I am trying to get the output as a 'List' of 1's & 0's

In[7]:= data = {0.25, 0.292893219, 0.5, 
   0.707106781, 0.75, 0, 0.25, 
   0.292893219, 0.5, 0.707106781, 
   0.75, 0, 0.25, 
   0.2928932190000002, 0.5, 
   0.7071067809999998, 0.75, 0, 
   0.25, 0.2928932190000002, 0.5, 
   0.7071067809999998, 0.75, 0, 0.5, 
   0.5857864380000004, 1, 
   1.4142135619999996, 1.5, 0, 0.5, 
   0.5857864380000004, 1, 
   1.4142135619999996, 1.5, 0, 0.5, 
   0.5857864379999995, 1, 
   1.4142135620000005, 1.5, 0, 0.5, 
   0.5857864399999997, 1, 
   1.4142135600000003, 1.5, 0, 0.75, 
   0.8786796599999995, 1.5, 
   2.1213203400000005, 2.25, 0, 
   0.75, 0.8786796599999995, 1.5, 
   2.1213203400000005, 2.25, 0, 
   0.75, 0.8786796599999995, 1.5, 
   2.1213203400000005, 2.25, 0, 
   0.75, 0.8786796599999995, 1.5, 
   2.1213203400000005, 2.25, 0}


In[8]:= Clear[testIf]
testIf[dataValue_] := 
  If[dataValue == 0, 0, 1]

In[11]:= testIf[data[[11]]]
Out[11]= 1

In[13]:= testIf[data[[12]]]
Out[13]= 0

These two above values are working fine, however I want to produce a 'List'.

In[12]:= testIf[data[[All]]]
Out[12]= If[{0.25, 0.292893219, 0.5, 
    0.707106781, 0.75, 0, 0.25, 
    0.292893219, 0.5, 0.707106781, 
    0.75, 0, 0.25, 
    0.2928932190000002, 0.5, 
    0.7071067809999998, 0.75, 0, 
    0.25, 0.2928932190000002, 0.5, 
    0.7071067809999998, 0.75, 0, 
    0.5, 0.5857864380000004, 1, 
    1.4142135619999996, 1.5, 0, 0.5, 
    0.5857864380000004, 1, 
    1.4142135619999996, 1.5, 0, 0.5, 
    0.5857864379999995, 1, 
    1.4142135620000005, 1.5, 0, 0.5, 
    0.5857864399999997, 1, 
    1.4142135600000003, 1.5, 0, 
    0.75, 0.8786796599999995, 1.5, 
    2.1213203400000005, 2.25, 0, 
    0.75, 0.8786796599999995, 1.5, 
    2.1213203400000005, 2.25, 0, 
    0.75, 0.8786796599999995, 1.5, 
    2.1213203400000005, 2.25, 0, 
    0.75, 0.8786796599999995, 1.5, 
    2.1213203400000005, 2.25, 0} == 
   0, 0, 1]

Any help or advice gratefully received.

Best Regards - Lea Rebanks...




  • Prev by Date: Re: Optimization in Mathmatica
  • Next by Date: Re: List complement operator
  • Previous by thread: Re: Find Upper Neighbor in a list
  • Next by thread: Re: Using 'IF' function on 'Lists' in Mathematica 6.01