Author Topic: matrix row and colum swap  (Read 8678 times)

0 Members and 2 Guests are viewing this topic.

Offline Drak

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 118
  • Rating: +2/-16
  • The color of choice for winners.
    • View Profile
matrix row and colum swap
« 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

Offline {AP}

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 981
  • Rating: +74/-3
  • I am Webmaster!
    • View Profile
    • Removed From Game
Re: matrix row and colum swap
« Reply #1 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.)
« Last Edit: February 07, 2009, 08:57:12 am by {AP} »

Offline Drak

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 118
  • Rating: +2/-16
  • The color of choice for winners.
    • View Profile
Re: matrix row and colum swap
« Reply #2 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)

Offline {AP}

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 981
  • Rating: +74/-3
  • I am Webmaster!
    • View Profile
    • Removed From Game
Re: matrix row and colum swap
« Reply #3 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]
}
« Last Edit: February 07, 2009, 12:35:33 pm by {AP} »

Offline Drak

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 118
  • Rating: +2/-16
  • The color of choice for winners.
    • View Profile
Re: matrix row and colum swap
« Reply #4 on: February 07, 2009, 12:41:42 pm »
alrighty! thanks  :D

Offline {AP}

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 981
  • Rating: +74/-3
  • I am Webmaster!
    • View Profile
    • Removed From Game
Re: matrix row and colum swap
« Reply #5 on: February 07, 2009, 12:42:35 pm »
No problem, man.
If you ever have any other questions, feel free to ask. =D

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: matrix row and colum swap
« Reply #6 on: February 07, 2009, 12:49:42 pm »
Mmm i wonder if this could be used for a rotating tilemap...

Offline {AP}

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 981
  • Rating: +74/-3
  • I am Webmaster!
    • View Profile
    • Removed From Game
Re: matrix row and colum swap
« Reply #7 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.

Offline Speler

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 857
  • Rating: +6/-2
    • View Profile
Re: matrix row and colum swap
« Reply #8 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 :/

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: matrix row and colum swap
« Reply #9 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 ;)

Offline {AP}

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 981
  • Rating: +74/-3
  • I am Webmaster!
    • View Profile
    • Removed From Game
Re: matrix row and colum swap
« Reply #10 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. ^_~

Offline kalan_vod

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2715
  • Rating: +10/-0
    • View Profile
    • kalanrock.us
Re: matrix row and colum swap
« Reply #11 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.

Offline Drak

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 118
  • Rating: +2/-16
  • The color of choice for winners.
    • View Profile
Re: matrix row and colum swap
« Reply #12 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?

Offline kalan_vod

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2715
  • Rating: +10/-0
    • View Profile
    • kalanrock.us
Re: matrix row and colum swap
« Reply #13 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.

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: matrix row and colum swap
« Reply #14 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...
« Last Edit: February 12, 2009, 04:45:42 pm by calc84maniac »
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman