Programming challenges: processing vectors and matrices
|
02-14-2019, 11:11 AM
(This post was last modified: 02-14-2019 12:57 PM by pier4r.)
Post: #1
|
|||
|
|||
Programming challenges: processing vectors and matrices
Spin off of the thread "processing lists!" (somewhen there will be also processing strings)
In particular due to the observation that editing a pre allocated vector on the 50g (RPL) emulator is much faster than editing lists. Now for the little that I know the data structure with the most expressive tools on the RPL platform are lists. Especially with the additional libraries LSORT, goferlist, listExt plus the very useful built in RPL commands (DOSUBS, DOLIST, STREAM, \GSLIST (sigma list), ETC). (if one knows more, please contribute here). The following challenges can be extended also to other systems (prime, 71 basic, RPN models and what not) if those lack functions to achieve the wanted result. The basic approach is to "fill the gap" when compared to list operations. Note(s) - array = normal vector. Row or column vector are actually matrices. - If possible, avoid going through an operation using lists as manipulative mean. - presume that the input has at least 100 elements (unless unlikely or otherwise stated). #1 Sum the elements in a vector Input: a vector. Output: the sum of the elements in the vector. Inspiration: sigma list or \GSLIST Example(s): [ 1 2 3 ] -> 6 #2 Difference between adjacent values of the vector Input: a vector. Output: a vector of where the element in position i is equal to the difference of inputVector[i+1] - inputVector[i] Inspiration: delta list or \GDLIST Example(s): [ 1 3 5 ] -> [ 2 2 ] #3 Product of the elements Input: a vector. Output: the product of the elements in the vector Inspiration: pi list or \GPLIST Example(s): [ 1 3 5 ] -> 15 #4 reverse the elements of a vector Input: a vector. Output: the input vector with the elements reversed Inspiration: REVLIST Example(s): [ 1 3 5 ] -> [ 5 3 1 ] #5 (hard) iterating through a vector and apply a certain logic through it Input: L3: a vector. L2: number of elements to process together L1: logic to apply (a program) Output: L1: another vector result from the logic applied. If the result is only one number, a vector that contains it. Inspiration: STREAM, DOSUBS (without NSUB, ENDSUB), MAP, List parallel processing (50g AUR section F) #6 Max in a vector input: L1: a vector. output L1: the maximum element in it. Inspiration: LMAX (listExt). Also AUR 50g 2-16 as possible comparison #7 Min in a vector input: L1: a vector. output L1: the minimum element in it. Inspiration: LMIN (listExt). Also AUR 50g 2-16 as possible comparison #8 Median of a vector input: L1: a vector. output L1: the median element in it Inspiration: http://www.hpmuseum.org/forum/thread-114...#pid104441 #8.1 Percentile of a vector input: L1: a vector. L2: a value between 0 and 100 output L1: the n-th percentile in the vector. Inspiration: http://www.hpmuseum.org/forum/thread-114...#pid104441 #9 SORT a vector input: L1: a vector. output L1: the vector sorted with the values ascending. Inspiration: SORT, LSORT #10 Create a vector given an integer sequence input L3: minValue L2: maxValue L1: step output L1: a vector Inspiration: LSEQR (listExt) #11 Create a vector given a function input L4: minValue L3: maxValue L2: step L1: program that implements f(x) with x in [minValue, maxvalue] output L1: a vector in the form [ f(minValue), f(minvalue+step), f(minValue+2*step), ..., f(maxValue)] Inspiration: SEQ # Hopefully many more will be added. Wikis are great, Contribute :) |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)