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


Groups > comp.soft-sys.math.mathematica > #6951

Re: How to get elements satisfying specific condition from a list

From Bill Rowe <readnews@sbcglobal.net>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: How to get elements satisfying specific condition from a list
Date 2011-12-05 23:49 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <jbjl9n$e7e$1@smc.vnet.net> (permalink)

Show all headers | View raw


On 12/4/11 at 2:51 AM, e-changb@hanmail.net (e-changb) wrote:

>Hi, please help me if you can.. Let

>B:= Table[{x, y}, {x, 1, 6}, {y, 1, 6}]

A couple of comments here. It is wiser to use lower case letters
for your variables so as to avoid conflicts with built in
symbols. Also, no need for SetDelayed (:=) here. Set (=) will do
what you want.

>It is clear that B has 36 elements.

>I want to get the list of elements satisfying 'the first component +
>second component is bigger than 9'

>so that the answer is

>{{5,5},{5,6},{6,5},{6,6}}.

 From your description both {4,6} and {6,4} should be included.
In any case, what you want can be done as:

In[12]:= b = Table[{x, y}, {x, 1, 6}, {y, 1, 6}];
Cases[Flatten[b, 1], _?(Total@# > 9 &)]

Out[13]= {{4, 6}, {5, 5}, {5, 6}, {6, 4}, {6, 5}, {6, 6}}

Or a little more efficiently as:

In[14]:= b = Tuples[Range[6], {2}];
Cases[b, _?(Total@# > 9 &)]

Out[15]= {{4, 6}, {5, 5}, {5, 6}, {6, 4}, {6, 5}, {6, 6}}

>In fact, I have no idea for following even simpler problem. : Let A
>be a set of all natural numbers less than 10. Find every element
>whose squre root is bigger than 2. (needless to say the answer is
>{5,6,7,8,9})

This could be done as:

In[16]:= Cases[Range[10], _?(2 < Sqrt[#] &)]

Out[16]= {5,6,7,8,9,10}

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re: How to get elements satisfying specific condition from a list Bill Rowe <readnews@sbcglobal.net> - 2011-12-05 23:49 +0000

csiph-web