Formula for converting a linear index to its mirrored counterpart on the other side of the diagonal in a symmetric matrix
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
IâÂÂm looking for a formula which given a column-major linear index to an element in a symmetric $n times n$ matrix returns an index pointing to the corresponding location on the opposite side of the diagonal of the same matrix.
Say for example I have a matrix:
$$
A =
beginbmatrix
0 & 1 &2 \
1 & 0 & 2 \
2 & 2 & 0
endbmatrix
$$
And I enter $0$ into the formula, I would need it to return $0$ (since index $0$ is on the diagonal).
If I enter $1$ to the formula, I would need it to return $3$, since index $3$ points to the same location but mirrored to the opposite side of the diagonal.
If I enter $2$, it should return $6$. And so on...
This exact question has been asked before, but with row-major indexing instead of column-major. However, as far as I can tell, the accepted and upvoted answer on that tread is completely wrong so it offers little help.
Does anyone know how to solve this?
matrices symmetric-matrices
add a comment |Â
up vote
0
down vote
favorite
IâÂÂm looking for a formula which given a column-major linear index to an element in a symmetric $n times n$ matrix returns an index pointing to the corresponding location on the opposite side of the diagonal of the same matrix.
Say for example I have a matrix:
$$
A =
beginbmatrix
0 & 1 &2 \
1 & 0 & 2 \
2 & 2 & 0
endbmatrix
$$
And I enter $0$ into the formula, I would need it to return $0$ (since index $0$ is on the diagonal).
If I enter $1$ to the formula, I would need it to return $3$, since index $3$ points to the same location but mirrored to the opposite side of the diagonal.
If I enter $2$, it should return $6$. And so on...
This exact question has been asked before, but with row-major indexing instead of column-major. However, as far as I can tell, the accepted and upvoted answer on that tread is completely wrong so it offers little help.
Does anyone know how to solve this?
matrices symmetric-matrices
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
IâÂÂm looking for a formula which given a column-major linear index to an element in a symmetric $n times n$ matrix returns an index pointing to the corresponding location on the opposite side of the diagonal of the same matrix.
Say for example I have a matrix:
$$
A =
beginbmatrix
0 & 1 &2 \
1 & 0 & 2 \
2 & 2 & 0
endbmatrix
$$
And I enter $0$ into the formula, I would need it to return $0$ (since index $0$ is on the diagonal).
If I enter $1$ to the formula, I would need it to return $3$, since index $3$ points to the same location but mirrored to the opposite side of the diagonal.
If I enter $2$, it should return $6$. And so on...
This exact question has been asked before, but with row-major indexing instead of column-major. However, as far as I can tell, the accepted and upvoted answer on that tread is completely wrong so it offers little help.
Does anyone know how to solve this?
matrices symmetric-matrices
IâÂÂm looking for a formula which given a column-major linear index to an element in a symmetric $n times n$ matrix returns an index pointing to the corresponding location on the opposite side of the diagonal of the same matrix.
Say for example I have a matrix:
$$
A =
beginbmatrix
0 & 1 &2 \
1 & 0 & 2 \
2 & 2 & 0
endbmatrix
$$
And I enter $0$ into the formula, I would need it to return $0$ (since index $0$ is on the diagonal).
If I enter $1$ to the formula, I would need it to return $3$, since index $3$ points to the same location but mirrored to the opposite side of the diagonal.
If I enter $2$, it should return $6$. And so on...
This exact question has been asked before, but with row-major indexing instead of column-major. However, as far as I can tell, the accepted and upvoted answer on that tread is completely wrong so it offers little help.
Does anyone know how to solve this?
matrices symmetric-matrices
edited Aug 20 at 10:36
JayTuma
1,333118
1,333118
asked Aug 20 at 9:41
Petahanks
31
31
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
I take two steps to solve the problem:
1) Find the matrix index in the form of $(i, j)$ corresponding to the number entered
2) swap $(i, j)$ to $(j, i)$, which is for "mirroring". Find the index of the vector form of the column based matrix.
The solution works for $1$ based, but can be converted easily to $0$ based since their difference for the same location is $1$.
notation
$leftlfloor fracln rightrfloor = l // n$
Let $(i_l, j_l)$ be a mapping:
beginequation
labelvecmap
beginsplit
& (i_l, j_l): 1, ldots, n^2 to 1, ldots, ntimes 1, ldots, n\
& l to (i_l, j_l)\
& i_l = l - n(j_l-1) \
& j_l = leftlfloor fracln rightrfloor \
endsplit
endequation
For exmaple:
$$
beginsplit
&l = 1, (i_1, j_1) = (1, 1)\
&l = n, (i_l, j_l) = (n, 1)\
&l = n+1, (i_l, j_l) = (1, 2)\
&l = n^2, (i_l, j_l) = (n, n)\
endsplit
$$
We want the "$l_*$" of $(j_l, i_l)$, which is $l_* = n(i_l - 1) + j_l$.
Explanation
Enter $i = 2$, the corresponding $l=3$ because I assume the starting index of series is 1 rather than 0. In your example, n = 3. Hence $i_l = 3, j_l = 1$, this gives $l_* = 3(3- 1) + 1 = 7$. Again because starting index is 1, converting by minus 1 you get 6.
IâÂÂm afraid I donâÂÂt understand at all how what you have written solves the problem, if it does, could you please clarify how? To me it looks like you have just written a formula for subscript to linear indexing conversion which seems to have nothing to do with finding the mirrored index on the opposite of the diagonal. It also appears that you are working with 1-based indexing which is also incompatible with the question
â Petahanks
Aug 20 at 10:16
Please see explanation in the answer
â kevin
Aug 20 at 10:26
Ah! I get it now, it seems to work perfectly. Elegantly done, thank you!
â Petahanks
Aug 20 at 10:56
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
I take two steps to solve the problem:
1) Find the matrix index in the form of $(i, j)$ corresponding to the number entered
2) swap $(i, j)$ to $(j, i)$, which is for "mirroring". Find the index of the vector form of the column based matrix.
The solution works for $1$ based, but can be converted easily to $0$ based since their difference for the same location is $1$.
notation
$leftlfloor fracln rightrfloor = l // n$
Let $(i_l, j_l)$ be a mapping:
beginequation
labelvecmap
beginsplit
& (i_l, j_l): 1, ldots, n^2 to 1, ldots, ntimes 1, ldots, n\
& l to (i_l, j_l)\
& i_l = l - n(j_l-1) \
& j_l = leftlfloor fracln rightrfloor \
endsplit
endequation
For exmaple:
$$
beginsplit
&l = 1, (i_1, j_1) = (1, 1)\
&l = n, (i_l, j_l) = (n, 1)\
&l = n+1, (i_l, j_l) = (1, 2)\
&l = n^2, (i_l, j_l) = (n, n)\
endsplit
$$
We want the "$l_*$" of $(j_l, i_l)$, which is $l_* = n(i_l - 1) + j_l$.
Explanation
Enter $i = 2$, the corresponding $l=3$ because I assume the starting index of series is 1 rather than 0. In your example, n = 3. Hence $i_l = 3, j_l = 1$, this gives $l_* = 3(3- 1) + 1 = 7$. Again because starting index is 1, converting by minus 1 you get 6.
IâÂÂm afraid I donâÂÂt understand at all how what you have written solves the problem, if it does, could you please clarify how? To me it looks like you have just written a formula for subscript to linear indexing conversion which seems to have nothing to do with finding the mirrored index on the opposite of the diagonal. It also appears that you are working with 1-based indexing which is also incompatible with the question
â Petahanks
Aug 20 at 10:16
Please see explanation in the answer
â kevin
Aug 20 at 10:26
Ah! I get it now, it seems to work perfectly. Elegantly done, thank you!
â Petahanks
Aug 20 at 10:56
add a comment |Â
up vote
0
down vote
accepted
I take two steps to solve the problem:
1) Find the matrix index in the form of $(i, j)$ corresponding to the number entered
2) swap $(i, j)$ to $(j, i)$, which is for "mirroring". Find the index of the vector form of the column based matrix.
The solution works for $1$ based, but can be converted easily to $0$ based since their difference for the same location is $1$.
notation
$leftlfloor fracln rightrfloor = l // n$
Let $(i_l, j_l)$ be a mapping:
beginequation
labelvecmap
beginsplit
& (i_l, j_l): 1, ldots, n^2 to 1, ldots, ntimes 1, ldots, n\
& l to (i_l, j_l)\
& i_l = l - n(j_l-1) \
& j_l = leftlfloor fracln rightrfloor \
endsplit
endequation
For exmaple:
$$
beginsplit
&l = 1, (i_1, j_1) = (1, 1)\
&l = n, (i_l, j_l) = (n, 1)\
&l = n+1, (i_l, j_l) = (1, 2)\
&l = n^2, (i_l, j_l) = (n, n)\
endsplit
$$
We want the "$l_*$" of $(j_l, i_l)$, which is $l_* = n(i_l - 1) + j_l$.
Explanation
Enter $i = 2$, the corresponding $l=3$ because I assume the starting index of series is 1 rather than 0. In your example, n = 3. Hence $i_l = 3, j_l = 1$, this gives $l_* = 3(3- 1) + 1 = 7$. Again because starting index is 1, converting by minus 1 you get 6.
IâÂÂm afraid I donâÂÂt understand at all how what you have written solves the problem, if it does, could you please clarify how? To me it looks like you have just written a formula for subscript to linear indexing conversion which seems to have nothing to do with finding the mirrored index on the opposite of the diagonal. It also appears that you are working with 1-based indexing which is also incompatible with the question
â Petahanks
Aug 20 at 10:16
Please see explanation in the answer
â kevin
Aug 20 at 10:26
Ah! I get it now, it seems to work perfectly. Elegantly done, thank you!
â Petahanks
Aug 20 at 10:56
add a comment |Â
up vote
0
down vote
accepted
up vote
0
down vote
accepted
I take two steps to solve the problem:
1) Find the matrix index in the form of $(i, j)$ corresponding to the number entered
2) swap $(i, j)$ to $(j, i)$, which is for "mirroring". Find the index of the vector form of the column based matrix.
The solution works for $1$ based, but can be converted easily to $0$ based since their difference for the same location is $1$.
notation
$leftlfloor fracln rightrfloor = l // n$
Let $(i_l, j_l)$ be a mapping:
beginequation
labelvecmap
beginsplit
& (i_l, j_l): 1, ldots, n^2 to 1, ldots, ntimes 1, ldots, n\
& l to (i_l, j_l)\
& i_l = l - n(j_l-1) \
& j_l = leftlfloor fracln rightrfloor \
endsplit
endequation
For exmaple:
$$
beginsplit
&l = 1, (i_1, j_1) = (1, 1)\
&l = n, (i_l, j_l) = (n, 1)\
&l = n+1, (i_l, j_l) = (1, 2)\
&l = n^2, (i_l, j_l) = (n, n)\
endsplit
$$
We want the "$l_*$" of $(j_l, i_l)$, which is $l_* = n(i_l - 1) + j_l$.
Explanation
Enter $i = 2$, the corresponding $l=3$ because I assume the starting index of series is 1 rather than 0. In your example, n = 3. Hence $i_l = 3, j_l = 1$, this gives $l_* = 3(3- 1) + 1 = 7$. Again because starting index is 1, converting by minus 1 you get 6.
I take two steps to solve the problem:
1) Find the matrix index in the form of $(i, j)$ corresponding to the number entered
2) swap $(i, j)$ to $(j, i)$, which is for "mirroring". Find the index of the vector form of the column based matrix.
The solution works for $1$ based, but can be converted easily to $0$ based since their difference for the same location is $1$.
notation
$leftlfloor fracln rightrfloor = l // n$
Let $(i_l, j_l)$ be a mapping:
beginequation
labelvecmap
beginsplit
& (i_l, j_l): 1, ldots, n^2 to 1, ldots, ntimes 1, ldots, n\
& l to (i_l, j_l)\
& i_l = l - n(j_l-1) \
& j_l = leftlfloor fracln rightrfloor \
endsplit
endequation
For exmaple:
$$
beginsplit
&l = 1, (i_1, j_1) = (1, 1)\
&l = n, (i_l, j_l) = (n, 1)\
&l = n+1, (i_l, j_l) = (1, 2)\
&l = n^2, (i_l, j_l) = (n, n)\
endsplit
$$
We want the "$l_*$" of $(j_l, i_l)$, which is $l_* = n(i_l - 1) + j_l$.
Explanation
Enter $i = 2$, the corresponding $l=3$ because I assume the starting index of series is 1 rather than 0. In your example, n = 3. Hence $i_l = 3, j_l = 1$, this gives $l_* = 3(3- 1) + 1 = 7$. Again because starting index is 1, converting by minus 1 you get 6.
edited Aug 20 at 10:48
answered Aug 20 at 9:58
kevin
986
986
IâÂÂm afraid I donâÂÂt understand at all how what you have written solves the problem, if it does, could you please clarify how? To me it looks like you have just written a formula for subscript to linear indexing conversion which seems to have nothing to do with finding the mirrored index on the opposite of the diagonal. It also appears that you are working with 1-based indexing which is also incompatible with the question
â Petahanks
Aug 20 at 10:16
Please see explanation in the answer
â kevin
Aug 20 at 10:26
Ah! I get it now, it seems to work perfectly. Elegantly done, thank you!
â Petahanks
Aug 20 at 10:56
add a comment |Â
IâÂÂm afraid I donâÂÂt understand at all how what you have written solves the problem, if it does, could you please clarify how? To me it looks like you have just written a formula for subscript to linear indexing conversion which seems to have nothing to do with finding the mirrored index on the opposite of the diagonal. It also appears that you are working with 1-based indexing which is also incompatible with the question
â Petahanks
Aug 20 at 10:16
Please see explanation in the answer
â kevin
Aug 20 at 10:26
Ah! I get it now, it seems to work perfectly. Elegantly done, thank you!
â Petahanks
Aug 20 at 10:56
IâÂÂm afraid I donâÂÂt understand at all how what you have written solves the problem, if it does, could you please clarify how? To me it looks like you have just written a formula for subscript to linear indexing conversion which seems to have nothing to do with finding the mirrored index on the opposite of the diagonal. It also appears that you are working with 1-based indexing which is also incompatible with the question
â Petahanks
Aug 20 at 10:16
IâÂÂm afraid I donâÂÂt understand at all how what you have written solves the problem, if it does, could you please clarify how? To me it looks like you have just written a formula for subscript to linear indexing conversion which seems to have nothing to do with finding the mirrored index on the opposite of the diagonal. It also appears that you are working with 1-based indexing which is also incompatible with the question
â Petahanks
Aug 20 at 10:16
Please see explanation in the answer
â kevin
Aug 20 at 10:26
Please see explanation in the answer
â kevin
Aug 20 at 10:26
Ah! I get it now, it seems to work perfectly. Elegantly done, thank you!
â Petahanks
Aug 20 at 10:56
Ah! I get it now, it seems to work perfectly. Elegantly done, thank you!
â Petahanks
Aug 20 at 10:56
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2888590%2fformula-for-converting-a-linear-index-to-its-mirrored-counterpart-on-the-other-s%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password