Author Topic: Matrix Help  (Read 8525 times)

0 Members and 1 Guest are viewing this topic.

Offline cooliojazz

  • Support Staff
  • LV7 Elite (Next: 700)
  • *******
  • Posts: 619
  • Rating: +66/-9
  • I omnoms on your soul
    • View Profile
    • Unreal Phantasies
Matrix Help
« on: January 29, 2010, 10:39:27 pm »
OK, say I wanted to take a matrix
[1,2,3]
[4,7,3]
[9,5,6]
and take off the first row so it was
[2,3]
[7,3]
[5,6]
how could i do this?  The only way I've been able to do this would be using Matrix to list, but that takes a lot of space and is slow, so...
Spoiler For Random signess:
You can not beat my skills.
Trust me.
So don't even try.
And remember never to trust someone who says, "Trust me."

TI File Editor Progress: Remade in java like a boss. 50% we'll call it? IDK =P
Java Libraries: JIRC - 90% JTIF - 5%
TI Projects: Unreal Notator - -5000%
Nomcraft, a Bukkit mod
Some of the music I write can be found here | The Rest Should Be Here (Bandcamp)

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Matrix Help
« Reply #1 on: January 29, 2010, 11:19:35 pm »
You could use a for( loop, but I have no idea if it's faster.
Input and Output in [A]
:dim([A]->L1
:For(A,1,L1(1
:For(B,2,L1(2
:[A](A,B->[A](A,B-1
:End
:End
:{L1(1),L1(2)-1->dim([A]

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Matrix Help
« Reply #2 on: January 30, 2010, 12:19:30 am »
Hmmm, I'm tempted to do some sort of fancy list manipulations and such, but I have another idea that may or may not work.

I assume these values will be accessed at some time in the program, so what I'm thinking is instead of changing the matrix, you could have a 'shift' variable that you can change.  Instead of saying [A](A,B) you would have [A](A+S,B) where S is the shift variable.  To simulate shifting the matrix over by one, you could instead just increase S by 1.

Offline cooliojazz

  • Support Staff
  • LV7 Elite (Next: 700)
  • *******
  • Posts: 619
  • Rating: +66/-9
  • I omnoms on your soul
    • View Profile
    • Unreal Phantasies
Re: Matrix Help
« Reply #3 on: January 30, 2010, 12:20:33 am »
Hmm, i think that would be slower than
:[A]T->[A]
:Matr->Lst([A],L1,L2,L3)
:Lst->Matr(L2,L3,[A])
:[A]T->[A]
Which is what i'm doing. I could be wrong tho.

EDIT: Grr, 3 seconds BuilderBoy :P
The problem with doing that tho, is that i'm also adding a random row on the end, so the matrix woul grow to unreasonable proportions quickly. (really line 3 is :Lst->Matr(L2,L3,L1,[A]) where L1 is a new random line.) and no, those values are now null and void.
« Last Edit: January 30, 2010, 12:23:49 am by cooliojazz »
Spoiler For Random signess:
You can not beat my skills.
Trust me.
So don't even try.
And remember never to trust someone who says, "Trust me."

TI File Editor Progress: Remade in java like a boss. 50% we'll call it? IDK =P
Java Libraries: JIRC - 90% JTIF - 5%
TI Projects: Unreal Notator - -5000%
Nomcraft, a Bukkit mod
Some of the music I write can be found here | The Rest Should Be Here (Bandcamp)

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Matrix Help
« Reply #4 on: January 30, 2010, 01:04:10 am »
Alrighty then, what you need is a radial List!

Basicaly instead of moving the Matrix around so that the begining is at colomn 1, you move a pointer around that says where column 1 is.  Does that make sense?  I can run up some code if you like.

Offline cooliojazz

  • Support Staff
  • LV7 Elite (Next: 700)
  • *******
  • Posts: 619
  • Rating: +66/-9
  • I omnoms on your soul
    • View Profile
    • Unreal Phantasies
Re: Matrix Help
« Reply #5 on: January 30, 2010, 01:09:06 am »
Not really.  Could you give a coded example?
Spoiler For Random signess:
You can not beat my skills.
Trust me.
So don't even try.
And remember never to trust someone who says, "Trust me."

TI File Editor Progress: Remade in java like a boss. 50% we'll call it? IDK =P
Java Libraries: JIRC - 90% JTIF - 5%
TI Projects: Unreal Notator - -5000%
Nomcraft, a Bukkit mod
Some of the music I write can be found here | The Rest Should Be Here (Bandcamp)

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Matrix Help
« Reply #6 on: January 30, 2010, 02:08:53 am »
Sure.  I used this technique on a snake game i made.  It s prime example of how you want to move a whole bunch of elements down a list without losing much speed.

So here we have a list of 10 numbers (I'll use lists, but it still applies to matrixes)

Code: [Select]
{1,2,3,4,5,6,7,8,9,0->L1
20->S                                //We set the shift to 20.  If it goes negative, bad things happen :P
"1+10fPart((X+S)/10->Y1         //This is our magic formula, using modulus arithmetic, it gives us
                               //the element we want but accounts for the shift
                               //It is stored to Y1 for easy use :P
While 1

For(F,1,10                 //Just some simple code to display the list from 'start' to 'finish'
Output(1,F,L1(Y1(F           //But using the formula, so in perspective of the shift
End

Repeat Ans
getKey -> K
End

S + (K=24) - (k=26)    //You can change the shift with your arrow keys

End

Offline cooliojazz

  • Support Staff
  • LV7 Elite (Next: 700)
  • *******
  • Posts: 619
  • Rating: +66/-9
  • I omnoms on your soul
    • View Profile
    • Unreal Phantasies
Re: Matrix Help
« Reply #7 on: January 30, 2010, 02:21:10 am »
Well, thats useful if L1, or [A] is always the same, but what if its always changing?  Or does your code apply to that too? (I'm just not seein it man. :P)
Spoiler For Random signess:
You can not beat my skills.
Trust me.
So don't even try.
And remember never to trust someone who says, "Trust me."

TI File Editor Progress: Remade in java like a boss. 50% we'll call it? IDK =P
Java Libraries: JIRC - 90% JTIF - 5%
TI Projects: Unreal Notator - -5000%
Nomcraft, a Bukkit mod
Some of the music I write can be found here | The Rest Should Be Here (Bandcamp)

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Matrix Help
« Reply #8 on: January 30, 2010, 02:42:07 am »
Well let's look at it his way.  What this allows you to do is "rotate" the elements of a list through that list, and you can read and write to it normaly.  To do as you wanted, when you shifted the elements down, one would get pushed off the edge and go around to slot 10.  You can then overwrite it with your random value, and we have a scrolling list!

Offline cooliojazz

  • Support Staff
  • LV7 Elite (Next: 700)
  • *******
  • Posts: 619
  • Rating: +66/-9
  • I omnoms on your soul
    • View Profile
    • Unreal Phantasies
Re: Matrix Help
« Reply #9 on: January 30, 2010, 03:27:38 am »
Oh, ok, i see what you're saying. This would be amazing and exactly what i need... except that i cant have it wrap :(
Spoiler For Random signess:
You can not beat my skills.
Trust me.
So don't even try.
And remember never to trust someone who says, "Trust me."

TI File Editor Progress: Remade in java like a boss. 50% we'll call it? IDK =P
Java Libraries: JIRC - 90% JTIF - 5%
TI Projects: Unreal Notator - -5000%
Nomcraft, a Bukkit mod
Some of the music I write can be found here | The Rest Should Be Here (Bandcamp)

Offline Galandros

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1140
  • Rating: +42/-10
    • View Profile
Re: Matrix Help
« Reply #10 on: January 30, 2010, 08:24:19 am »
With lists, to get out the first element we use cumSum and /delta/List combo.

Can a similar thing be done in Matrices? I have to get the calc to test. I am pretty sure cumSum works with matrices but /delta/List don't.
Hobbing in calculator projects.

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Matrix Help
« Reply #11 on: January 30, 2010, 11:21:09 am »
Builderboy, that's great code!  I've done the same thing in dodge-the-asteroids games.  I've probably made 10 of them, and they keep getting faster. :)

Right you are Galandros.  I don't know if you can manipulate it with a formula, as that's used for lists. (Galandros, I know you know that, but that's for those who didn't know that.) :)
« Last Edit: January 30, 2010, 11:21:28 am by ztrumpet »

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Matrix Help
« Reply #12 on: January 30, 2010, 12:48:15 pm »
Oh, ok, i see what you're saying. This would be amazing and exactly what i need... except that i cant have it wrap :(

Hmmm, I'm not quite sure what you mean.  Here, take a look at this slightly modified code

Code: [Select]
{1,2,3,4,5,6,7,8,9,0->L1
0->S                               
"1+10fPart((X+S)/10->Y1          //yay magic formula
                             
While 1

For(F,1,10                  //Display the entire linked list so you can see whats going on
Output(1,F,L1(Y1(F           //Displays elements from 1 to 10
End
rand(20

S+1->S                        //Increase shift
randInt(0,9->L1(Y1(10        //Add random number onto the 'end' of the list, which is element 10

End

I believe that does exactly what you are looking for.  Do you see how it works?  The numbers do wrap every time i change the shift, but then i overwrite them with the new random number that is being added onto the end of the list (End of the list is element 10)

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Matrix Help
« Reply #13 on: January 30, 2010, 06:43:48 pm »
That code is genius!
Would it be faster if you had Y1 hard coded in?

Offline cooliojazz

  • Support Staff
  • LV7 Elite (Next: 700)
  • *******
  • Posts: 619
  • Rating: +66/-9
  • I omnoms on your soul
    • View Profile
    • Unreal Phantasies
Re: Matrix Help
« Reply #14 on: January 30, 2010, 08:54:17 pm »
Yes I see it, but I have to have
[1,2,3]
[2,3,4]
not say,
[2,3,1]
[3,4,2]
Here's an explanation: XLib Tilemap :P
Spoiler For Random signess:
You can not beat my skills.
Trust me.
So don't even try.
And remember never to trust someone who says, "Trust me."

TI File Editor Progress: Remade in java like a boss. 50% we'll call it? IDK =P
Java Libraries: JIRC - 90% JTIF - 5%
TI Projects: Unreal Notator - -5000%
Nomcraft, a Bukkit mod
Some of the music I write can be found here | The Rest Should Be Here (Bandcamp)