List Commands Library for 50g
|
09-27-2017, 11:47 AM
Post: #169
|
|||
|
|||
RE: List Commands Library for 50g
(09-26-2017 03:29 PM)DavidM Wrote:(09-26-2017 01:10 PM)pier4r Wrote: Request: given an ordered list (integer and/or reals), asearch function that returns the index of the closer value compared to the input. I can't see how. You can use Find or FindIndex to find the first element in the list that is within a certain amount of the desired value. Assuming the value you are searching for is in the variable n, you can do something like this: Code: \<< n - ABS .01 < \>> FindIndex which will find the index of the first element that is within .01 of the value of n, or 0. if no element meets that criterion. To find the closest value you can use the ListExt command KSORT like so: Code: DUP n - ABS KSORT HEAD SWAP HEAD which will leave the closest element on level one and the error on level 2. With regard to the thread that Pier is referring to, if the above code snippet is used with LSORT as the third argument to KSORT, it should be significantly faster than a binary search routine written in User RPL. John |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 5 Guest(s)