Very complex problem about matrices
This is quite complex.
Suppose I have two 3x3 matrices represented as squares on a grid. The squares have nine circles in them, at positions 1,1 ; 1,2 ; 1,3 ; 2,1 ; 2,2 ; 2,3 ; 3,1 ; 3,2 ; 3,3. Square A is located in the upper left corner, placed in such a way that its circle at position 3,3 intersects with the circle at 1,1 in Square B (located in the center of the grid.)
OK. Now, Square A will move towards the right until it reaches the stage at which its circle at 3,1 intersects with the circle of Square B at 1,3. Next, Square A will be shifted down so that points 2,1 and 3,1 on Square A intersect with points 1,3 and 2,3 on Square B, respectively. Now Square A will move all the way to the left until it reaches the stage at which points 2,3 and 3,3 on Square A intersect with points 1,1 and 2,1 on Square B, respectively. Once again, Square A will be moved down and it will shift towards the right, move down, etc. The process ends when Square A is located at the bottom right corner, its circle at point 1,1 intersecting with the circle at point 3,3 of Square B. In sum, Square A will follow a snake trail/zig-zag (from the left all the way to the right, down one unit, then all the way to the left, down one unit, then all the way to the right, etc.)
OK. In total, there are 81 intersections (3^4). 9 of those occur at Stage 1 (while it is moving to the right), 18 occur at Stage 2 (moving to the left), 27 occur at stage 3 (moving to the right once again), 18 at Stage 4, and finally 9 more at Stage 5.
I've begun to make a table that illustrates the concept. It maps the intersections of the points.
Square B / Square A
#.....Row...Col...Row...Col
----------------------------
01..... 1..... 1..... 3..... 3
02..... 1..... 1..... 3..... 2
03..... 1..... 2..... 3..... 3
04..... 1..... 1..... 3..... 1
05..... 1..... 2..... 3..... 2
06..... 1..... 3..... 3..... 3
07..... 1..... 2..... 3..... 1
08..... 1..... 3..... 3..... 2
09..... 1..... 3..... 3..... 1
10..... 1..... 3..... 2..... 1
11..... 2..... 3..... 3..... 1
12..... 2..... 2..... 1..... 3
13..... 2..... 1..... 1..... 2
14..... 2..... 2..... 3..... 2
15..... 2..... 2..... 3..... 1
(etc.)
Now, I would like to model this into a function... Actually, four functions. For example, I would like to supply the # and function 1 returns the SquareA.Row value; function 2 returns SquareA.Column value; function 3 returns SquareB.Row value; and function 4 returns SquareB.Column value.
NOTE: The table is just an example. I want the function to be modeled mathematically, and NOT based on the table. Basically I need to find the pattern...!
Can somebody help me?
I know that the way I explained all this makes it more complicated than it really is. Just try picturing in your mind how Square A moves about Square B.
Re: Very complex problem about matrices
In order to simplify things a bit, consider the matrix to be a 1-dimensional imitation of a 2d matrix, in such a way that element 1,1 will be 1; 1,2 will be 2; 1,3 will be 3; 2,1 will be 4; and so on.
In this case, the table would consist of two variables, one for Square A and one for Square B
A.....B
-------
1.....9
1.....8
2.....9
1.....7
2.....8
3.....9
2.....7
3.....8
3.....7
(etc.)
Re: Very complex problem about matrices
I was able to determine the values at certain stages of the table.
VB Code:
Private Type MatrixElement
AIndex As Integer
BIndex As Integer
End Type
Private Function RL(Stage As Integer) As MatrixElement
Static Subtract As Integer
Static NextA As Integer
Static IncInMid As Integer
If Stage = 1 Then IncInMid = 1
Select Case Stage
Case Is <= Dim2
RL.AIndex = NextA + 1
RL.BIndex = Dim2 - Subtract
If RL.AIndex = Dim1 Then
NextA = 0
Subtract = Subtract + 1
Else
NextA = RL.AIndex
End If
Case (Dim4 - Dim2) / 2 + 1 To (Dim4 - Dim2) / 2 + Dim2
RL.AIndex = IncInMid
RL.BIndex = IncInMid
IncInMid = IncInMid + 1
Case Is > Dim4 - Dim2
RL.BIndex = NextA + 1
RL.AIndex = Dim2 - Subtract
If RL.BIndex = Dim1 Then
NextA = 0
Subtract = Subtract + 1
Else
NextA = RL.BIndex
End If
Case Else
RL.AIndex = ? 'Need other calculations here
RL.BIndex = ? 'and here
End Select
If Stage = Dim2 Then Subtract = 0
If Stage = Dim4 Then
Subtract = 0
NextA = 0
IncInMid = 0
End If
End Function
However, much is still missing...... :sick:
Re: Very complex problem about matrices
Sorry for so many posts.. lol
But there's a simpler way to plot the table in thread reply #2:
B...A <---- Lol, I got these mixed up. Remember, B is the mobile one!
9...1
9...2
9...3
8...1
8...2
8...3
7...1
7...2
7...3
Up to this point, there seems to be a pattern... However, things change once the square shifts down:
4...3
7...6
3...5
2...4
8...5
7...5
etc.
There's no pattern!
I'll work on it a little bit more, and try to re-arrange the second part of the table...
1 Attachment(s)
Re: Very complex problem about matrices
Oddly enough there is a pattern (see picture). Arranging it differently, you get increasing numbers for B and decreasing for A.
Still, I was wondering if there is a *General Forula* that can account for all the stages of the process...
P.S. (lol): Is anybody confused? I am confused myself, so I imagine nobody at all can understand what it is I'm asking here... Please ask if you have any questions!
Re: Very complex problem about matrices
Hi,
The "pattern" will depend on what order you specify your points. It'd be quite easy to confuse things by picking the intersections at any given stage in a different order.
You seem to have the right sort of idea, so I don't know whether this will be of any help, but here goes.
At any stage of lateral movement, i.e. left-right, you have 5 possible positions before you move A down again.
Consider stage 1, A moves Right. The number of overlaps are as follows:
1 - 2 - 3 - 2 - 1. Then move down and go left:
2 - 4 - 6 - 4 - 2. Move down and go right:
3 - 6 - 9 - 6 - 3...etc.
So, can we work out how many overlaps there are at any given point? Yes: If "move"<=5, we are in the first row above. 6<= "move" <= 10 and we are in the second row. So you can just int("move"/5) to find out which row. The remainder will then be the position along the row, which is fairly obvious to determine (1, 2, 3, 2, 1 * stage number).
Once you know how many overlaps there are, the next question is: which points overlap? In your table in post 1, #02 and #03 are from the same move, so if you ask "What is #02?", I could give you #02 or #03, depending on how I enter them in the table. So you might want to think of another set of rules for that. Hence we'll just ask "Which points overlap in move 1, move 2 etc?"
In Stage 1, the only points overlapping are from Square A R3 and Square B R1.
In Stage 2, the points are SqA R2 and R3, Sq B R1 and R2. etc.
So, if we know which stage we're at (Int(move/5)), we can see which rows of Sq A must be involved and which of Sq B. In the case of Sq B, it's just that number of rows from the top. In the case of Sq A,it's that number from the bottom.
What about the columns? Well, if we know which part of the stage we're at (remainder of Int...), we can determine this. If we've only started the stage, there is 1 column, then 2, then 3, then 2, then 1. Then 1 etc.
We also need to know which way we're going..because this will determine whether we approach from the left or the right. You could do a Mod 2 on the Stage to find out whether it is odd or even. If even ,we're moving left, odd and we're moving right. Thus if we know we're going right, move 2 of the stage, we know that there have to be 2 columns overlapping (1..2..3..2..1) and they have to be the rightmost 2 of Sq A, the leftmost of Sq B.
Now we've worked out the rows and the columns: our selection of points is just the intersection of all of these. Just go through squares A and B independently and systematically and you'll work them all out.
Does that help?
zaza
Re: Very complex problem about matrices
Zaza,
That's exactly what I needed. Thanks a lot!
I'm going to start trying to code all that, but if you could help me get started, I'd greatly appreciate it. Thanks!