Matrix Rotation of elements - Algorithms - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: General Forum (/forum-4.html) +--- Thread: Matrix Rotation of elements - Algorithms (/thread-14156.html) |
Matrix Rotation of elements - Algorithms - Ángel Martin - 12-12-2019 02:37 PM For no particular reason I've been looking into some matrix operations not mainstream, such as the element rotation, or "layer rotation". Note this is not the same as the "Rotation Matrix" used in transfromations theory - [ or is it? Somehow these two are begging to be connected in my mind... ] Surely some scarce references exist (see here, here, and here) but I wonder if friendlier algorithms have been worked out that allow for an easier implementation using our trusted toolset in the Advantage and SandMatrix modules... So to clarify, I'm after a single-element rotation algorithm, either clockwise or anti-clockwise. Rotating the entire matrix 90 degrees is actually very simple using the transpose and column swapping , but a single element is much harder. Anyy inputs will be appreciated. RE: Matrix Rotation of elements - Algorithms - Csaba Tizedes - 12-12-2019 03:31 PM (12-12-2019 02:37 PM)Ángel Martin Wrote: I wonder if friendlier algorithms have been worked out Which units are in play? 48xx? My 39gII arrived this week - maybe that? Csaba RE: Matrix Rotation of elements - Algorithms - Ángel Martin - 12-12-2019 03:59 PM (12-12-2019 03:31 PM)Csaba Tizedes Wrote: Which units are in play? 48xx? My 39gII arrived this week - maybe that? RPN if possible... RE: Matrix Rotation of elements - Algorithms - Ángel Martin - 12-15-2019 06:16 AM here's a start, surely not the best approach but it seems to do the job: for an (m x n) matrix, the rotated matrix (one single step, clockwise) bij is given as follows:- FOR k = 0 TO int(m/2)-1 ; current layer FOR j = k+1 TO (n-1-k) ; top row rightwards b(1+k),(j+1) = a(1+k),j NEXT j FOR i = (1+k) TO (m-1-k) ; rightmost column downwards b(i+1),(n-k) = a i,(n-k) NEXT i FOR j = (n-k) TO (2+k) STEP -1 ; bottom row leftwards b(m-k),(j-1) = a(m-k),j NEXT j FOR i = (m-k) TO (2+k) STEP -1 ; leftfmost column upwards b(i-1),(1+k) = a i,(1+k) NEXT i NEXT k ; next layer Edited: corrected typos in indexes RE: Matrix Rotation of elements - Algorithms - Ángel Martin - 12-17-2019 10:46 AM I don't think I said it before but when it comes to this kind of programs I really hate RPN, or more appropriately I hate FOCAL (let's put the blame where it belongs). Really what in BASIC is a simple and quick affair (see previous post) becomes tricky, sticky and error prone beyond relief using FOCAL - all those sub-indexes and counters - all pitfall-ridden! Regardless, the routine is done at last - will post it in the program section in a couple of days. RE: Matrix Rotation of elements - Algorithms - Csaba Tizedes - 12-17-2019 02:22 PM My first idea was that it requires something "matrix-to-list" stuff and the lists can be more flexible manipulate. (I totally agree: for matrices the BASIC is better ) The second was, how the HP 15C reorganize the elements, when I change the dimension of the matrices?!? The third was I need only a "row-extractor" and I will use it to copy one row into list, than I transpose the matrix and again extract and transpose and extract... Or something similar, and of course I must to put back the rotated list elements with the same way: put-transpose-put-transpose... The fourth was: this is something "walking-inside-a-spirale-labirynth": I started in the center and if I found a wall, I turn left (or right) and again until I found the last element. If I copy the values into a list during my way, I can transform my matrix into a list. This is a good exercise, I will workin' on it - after this Friday... Csaba RE: Matrix Rotation of elements - Algorithms - Ángel Martin - 12-17-2019 03:51 PM I actually use a scratch matrix and copy elements one at a time from the source to the scratch, and when done do the bulk renaming source = scratch. Here's the routine. you need to be familiar with the SandMatrix functions (an extension of the Advantage, itself an extension of the CCD ARRAY group...). The element copying happens in LBL 05 towards the end of the program. PHP Code: 1 LBL "M<)R" RE: Matrix Rotation of elements - Algorithms - Valentin Albillo - 12-17-2019 04:18 PM . Hi, Ángel: (12-17-2019 10:46 AM)Ángel Martin Wrote: Really what in BASIC is a simple and quick affair (see previous post) becomes tricky, sticky and error prone beyond relief using FOCAL - all those sub-indexes and counters - all pitfall-ridden! Hey, "Mr. Translator", it's "beyond belief", not "beyond relief". The "r" is far from the "b" in the keyboard so that's unlikely to be a typo. After ruffling your feathers a little, this matrix rotation business is but a simple mapping and yes, it's done much more easily in BASIC than in SEAL-L, you're finally seeing the light ! Best regards. V. RE: Matrix Rotation of elements - Algorithms - Ángel Martin - 12-18-2019 06:29 AM (12-17-2019 04:18 PM)Valentin Albillo Wrote: Hey, "Mr. Translator", it's "beyond belief", not "beyond relief". The "r" is far from the "b" in the keyboard so that's unlikely to be a typo. Nope, in this instance I wrote exactly what I wanted to say: beyond relief with 'R"- I'm very aware of the idiom and other colloquial expressions but to me language is a fluid thing, so it'll be the day when I stop expressing in my own peculiar way - I ain't translating! I'm not saying that I don't make my regular dose of typos of course, but this time Sauron's eye has erred his aim ;=) à bientôt, ÁM PS. SEAL-L, uh? pretty clever but unorthodox ;-) RE: Matrix Rotation of elements - Algorithms - Paul Dale - 12-18-2019 07:05 AM Ángel, your typos are uncommon and your English is perfect |