Message Boards Message Boards

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

What's wrong with my pure function?

Posted 11 years ago
I want to obtain a list, {1,13,19,3}
o = {1, 7, 13, 19, 25, 31};

t = {1, 8, 5, 5, 9, 3};
a = 0.3
b = Max[t]
r = Min[t]
s = Select[o, t[[#]] <= (b + (a (r - b))) &]
This message appear
Part::partw: Part 7 of {1,8,5,5,9,3} does not exist. >>
POSTED BY: Vinicio Sevilla
4 Replies
Bill

The first question is true.
Second question is true.

Exactly i need select all values that are less than or equal to 6.6 in the list t and obtain a list with the corresponding values of list o.
Thanks again to Michael the pure function definition should be:
s = Pick[o, # <= b + a (r - b) & /@ t]

Regards
Vinicio
POSTED BY: Vinicio Sevilla
Thanks so much Michael is working now

Vinicio
POSTED BY: Vinicio Sevilla
Posted 11 years ago
There appear to be two parts to the question.

First, your function is going to select items which are less than or equal to 6.6.
Is that correct and what you expect?

Next, the Select will extract items from your list o one at a time and each of
those items will replace the # inside your function so your function will be
testing, one at a time, t[[1]], t[[7]], t[[13]]. t[[19]], t[[25]], t[[31]] where
1,7,13,19,25,31 are the values from o.
Is that correct and what you expect?

Now t only has six elements so only t[[1]],t[[2]]...t[[6]] can be obtained from t.

From this can you see how you need to change your function?

If not then can you explain step by step how you expect you should get 1,13,19,3?
Should that last number perhaps be 31?
POSTED BY: Bill Simpson
Posted 11 years ago
Hi Vinicio,

Change your last line to this:
s = Select[o, t[[Position[o, #][[1, 1]]]] <= (b + (a (r - b))) &]
Or preferably to this:
s = Pick[o, # <= b + a (r - b) & /@ t]
POSTED BY: Michael Hale
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