Message Boards Message Boards

0
|
5112 Views
|
4 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Make a list and remove the odd values?

Posted 4 years ago

Right now, I've been trying threshold[min_,max_]=Apply[Select[EvenQ],Range[min,max]

However, that's not working. It seems extremely difficult to create a list and change it in one go.

POSTED BY: Joseph Donovan
4 Replies
Posted 4 years ago

Well I am not very smart, see my photo, but that is interesting. I know it is a shot list and I guess zero is even so being very discrete . . .

In[3]:= n := 0

In[6]:= Case[{n, n + 1}, n]

Out[6]= Case[{0, 1}, 0]

wait . . .

In[3]:= n := 0

In[7]:= Case[{n, n + 1}, n + 1]

Out[7]= Case[{0, 1}, 1]
POSTED BY: Roger Wells

There are many ways to do this you can try:

Clear[threshold];
threshold[min_, max_] := DeleteCases[Range[min, max], _?OddQ]
POSTED BY: Hans Michel
Posted 4 years ago

why did this work, or in other words, what does this tell the interpreter to do that was different from how I typed it? Why was ":=" better than "="? and what is "_?"? Thanks for the answer!

POSTED BY: Joseph Donovan
Posted 4 years ago

Apply replaces the Head of an expression. Changing the Head to Select[EvenQ] results in this Select[EvenQ][1, 2, 3, 4, 5] which is invalid. You need this

threshold[min_, max_] := Range[min, max] // Select[EvenQ]
POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract