Matrix Rotation of elements - Algorithms
|
12-12-2019, 02:37 PM
Post: #1
|
|||
|
|||
Matrix Rotation of elements - Algorithms
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. "To live or die by your own sword one must first learn to wield it aptly." |
|||
12-12-2019, 03:31 PM
Post: #2
|
|||
|
|||
RE: Matrix Rotation of elements - Algorithms | |||
12-12-2019, 03:59 PM
Post: #3
|
|||
|
|||
RE: Matrix Rotation of elements - Algorithms
(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... "To live or die by your own sword one must first learn to wield it aptly." |
|||
12-15-2019, 06:16 AM
(This post was last modified: 12-16-2019 12:54 PM by Ángel Martin.)
Post: #4
|
|||
|
|||
RE: Matrix Rotation of elements - Algorithms
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 "To live or die by your own sword one must first learn to wield it aptly." |
|||
12-17-2019, 10:46 AM
(This post was last modified: 12-17-2019 10:47 AM by Ángel Martin.)
Post: #5
|
|||
|
|||
RE: Matrix Rotation of elements - Algorithms
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. "To live or die by your own sword one must first learn to wield it aptly." |
|||
12-17-2019, 02:22 PM
Post: #6
|
|||
|
|||
RE: Matrix Rotation of elements - Algorithms
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 |
|||
12-17-2019, 03:51 PM
(This post was last modified: 12-17-2019 04:04 PM by Ángel Martin.)
Post: #7
|
|||
|
|||
RE: Matrix Rotation of elements - Algorithms
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" "To live or die by your own sword one must first learn to wield it aptly." |
|||
12-17-2019, 04:18 PM
Post: #8
|
|||
|
|||
RE: Matrix Rotation of elements - Algorithms
.
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. All My Articles & other Materials here: Valentin Albillo's HP Collection |
|||
12-18-2019, 06:29 AM
(This post was last modified: 12-18-2019 06:36 AM by Ángel Martin.)
Post: #9
|
|||
|
|||
RE: Matrix Rotation of elements - Algorithms
(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 ;-) "To live or die by your own sword one must first learn to wield it aptly." |
|||
12-18-2019, 07:05 AM
Post: #10
|
|||
|
|||
RE: Matrix Rotation of elements - Algorithms
Ángel, your typos are uncommon and your English is perfect
|
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 6 Guest(s)