# What's wrong with my pure function?

Posted 9 years ago
3593 Views
|
4 Replies
|
0 Total Likes
|
 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.3b = Max[t]r = Min[t]s = Select[o, t[[#]] <= (b + (a (r - b))) &]This message appearPart::partw: Part 7 of {1,8,5,5,9,3} does not exist. >>
4 Replies
Sort By:
Posted 9 years ago
 BillThe 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]RegardsVinicio
Posted 9 years ago
 Thanks so much Michael is working nowVinicio
Posted 9 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 ofthose items will replace the # inside your function so your function will betesting, one at a time, t[[1]], t[[7]], t[[13]]. t[[19]], t[[25]], t[[31]] where1,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 9 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]