Omnimaga

Calculator Community => TI Calculators => TI-BASIC => Topic started by: Drak on February 07, 2009, 03:17:53 am

Title: matrix row and colum swap
Post by: Drak on February 07, 2009, 03:17:53 am
anyone know the fastest way to shift everything in a matrix around? like, moving rows up and down, and columns left and right? TI84+Basic [or asm.]

need it to play around with matricies
Title: Re: matrix row and colum swap
Post by: {AP} on February 07, 2009, 08:53:20 am
Well, there is the 'rowSwap()' command.
As for column sorting, rowSwap([A]T.

Syntax:
rowSwap([A],<number of first row you wanna swap>,<second one>
rowSwap([A]T,<number of first column you wanna swap>,<second one>

(P.S. Both rowSwap( and T are found under Matrix -> Math.)
Title: Re: matrix row and colum swap
Post by: Drak on February 07, 2009, 12:17:01 pm
Well, there is the 'rowSwap()' command.
As for column sorting, rowSwap([A]T.

Syntax:
rowSwap([A],<number of first row you wanna swap>,<second one>
rowSwap([A]T,<number of first column you wanna swap>,<second one>

(P.S. Both rowSwap( and T are found under Matrix -> Math.)


alright. what is "t" though? (it works, i just don't know what the name of it is... never seen it before)
Title: Re: matrix row and colum swap
Post by: {AP} on February 07, 2009, 12:24:45 pm
It's 'transpose'.
It swaps the rows and columns.
(e.g. Column 1 is now row 1, column 2 is row 2, etc.)
Code: [Select]
Visual Example:
[1,1]
[2,2]
becomes
[1,2]
[1,2]

Another:
[1,2,3]
[1,2,3]
[1,2,3]
becomes
[1,1,1]
[2,2,2]
[3,3,3]

Uneven:
[1,2]
[1,2]
[1,2]
becomes
[1,1,1]
[2,2,2]

{EDIT: The reason that it doesn't flip the whole matrix permanently is that is outputs into Ans. If you want it to stay transposed it'll be [A]T→[A]}

{EDIT2: To swap columns and save it it'll be
:rowSwap([A]T,x,y)T→[A]
}
Title: Re: matrix row and colum swap
Post by: Drak on February 07, 2009, 12:41:42 pm
alrighty! thanks  :D
Title: Re: matrix row and colum swap
Post by: {AP} on February 07, 2009, 12:42:35 pm
No problem, man.
If you ever have any other questions, feel free to ask. =D
Title: Re: matrix row and colum swap
Post by: DJ Omnimaga on February 07, 2009, 12:49:42 pm
Mmm i wonder if this could be used for a rotating tilemap...
Title: Re: matrix row and colum swap
Post by: {AP} on February 07, 2009, 01:11:39 pm
Wow... something I knew that Omni didn't?
I'm impressed with myself now. =D

Though that's actually a cool idea, omni.
If it wasn't for the fact that I'm not using ASCII for the map or more constant tiles, I'd try and implement it.
Title: Re: matrix row and colum swap
Post by: Speler on February 07, 2009, 01:13:45 pm
I'm trying to think of a good puzzle for dungeons that uses this.  Can't think of anything though :/
Title: Re: matrix row and colum swap
Post by: DJ Omnimaga on February 07, 2009, 01:36:47 pm
Wow... something I knew that Omni didn't?
I'm impressed with myself now. =D
Keep in mind that my peak of activity in calc programming was around late 2002 until late 2004, though ;)
Title: Re: matrix row and colum swap
Post by: {AP} on February 07, 2009, 01:41:51 pm
Wow... something I knew that Omni didn't?
I'm impressed with myself now. =D
Keep in mind that my peak of activity in calc programming was around late 2002 until late 2004, though ;)

Even so... I've looked up to you for a good deal of time now. ^_~
Title: Re: matrix row and colum swap
Post by: kalan_vod on February 08, 2009, 01:22:50 am
Yeah, I use that in my compression program (CIB). I think you still remember it kevin, transpose is quick too.
Title: Re: matrix row and colum swap
Post by: Drak on February 12, 2009, 12:53:57 am
stumped. it's incredibly slow to do a fornext to shift the entire thing down or up or left or right. anyone got any solutions?
Title: Re: matrix row and colum swap
Post by: kalan_vod on February 12, 2009, 10:16:12 am
Contact a Asm programmer, in asm this will move so quickly..But in basic you are not going to get much faster.
Title: Re: matrix row and colum swap
Post by: calc84maniac on February 12, 2009, 04:25:37 pm
I'm going to try and figure out a hacky way to do this in pure Basic. I have an idea of how it's going to work.

Edit: Never mind, it turned out even slower than just switching the rows, and hogs way more memory as well. I tried to use the exchange matrix method.

Edit2: Are you kidding? The rowswap method seems pretty fast to me. It took less than a second for every case I tried...
Title: Re: matrix row and colum swap
Post by: Drak on February 12, 2009, 09:21:24 pm
needs to be split second. like, no time at all. what way did yo ugo about doing it? (code pls kthnx ps im not a spie i no ninja ur koad.)
Title: Re: matrix row and colum swap
Post by: DJ Omnimaga on February 12, 2009, 11:33:26 pm
Maybe he got a lot of stuff going on in his game besides the row swapping. I might experiment with that feature someday though, to see if it couldnt be useful for certain games
Title: Re: matrix row and colum swap
Post by: Galandros on February 13, 2009, 02:00:36 pm
DJ you didn't know matrix commands? When I discovered I was an ignorant about them, I rushed reading TI-BD...

Anyway, those commands seem nicely fast for me. the "t" stands for transpose iirc.
Title: Re: matrix row and colum swap
Post by: {AP} on February 13, 2009, 02:04:53 pm
For future reference...

[A]T
Code: [Select]
[A][sup]T[/sup]

Code: [Select]
Alt+26 (on the numpad with Num Lock on)
Hold Alt, press 2 then 6, then let go of Alt.
Title: Re: matrix row and colum swap
Post by: DJ Omnimaga on February 13, 2009, 04:10:10 pm
DJ you didn't know matrix commands? When I discovered I was an ignorant about them, I rushed reading TI-BD...

Anyway, those commands seem nicely fast for me. the "t" stands for transpose iirc.
I know how to use matrices, but I never used the other commands except for Fill(, Dim( and T, because they weren't of any use for me in any of the old games I made. Same for IS</DS>. I only learned about it when I had no choice to use it (TI-81 Illusiat)