Determine if Matrix can be permutated into Block Diagonal Matrix












2












$begingroup$


Is there a way to determine if by permutation of rows and columns a matrix can be transformed into a block-diagonal matrix (EDIT: with more than one block)? For example the following matrix



begin{bmatrix}
0 &0 &7 &0 &0 \
0 &0 &0 &0 &3 \
5 &0 &0 &1 &0\
0 &0 &2 &0 &0 \
0 &1 &0 &0 &0
end{bmatrix}

EDIT: set to 0 element in 2nd row that was =2.



By permuting first row with last row and first column with last column can be transformed into the following block-diagonal matrix.
begin{bmatrix}
0 &1 &0 &0 &0 \
3 &0 &0 &0 &0 \
0 &0 &0 &1 &5\
0 &0 &2 &0 &0 \
0 &0 &7 &0 &0
end{bmatrix}

Is there an algorithm to find out if it is possible and do it, or to determine the permutation matrix?



My problem is about representing points scored by players against each other in. I need to determine the relative strength of players by comparing their scores. Imagine the matrix is the score of a player against another player. Each row is a player, and each column is a player. The diagonal is empty, or zero. If nobody in a group of player has played against anybody in the other group of players, then I cannot rank one group against the other group, because I do not know their relative strength. So I'm trying to eventually decompose the matrix into several if they exist. In the example above they would be the two following ones
begin{bmatrix}
0 &1 &0 &0 &0 \
3 &0 &0 &0 &0 \
0 &0 &0 &0 &0\
0 &0 &0 &0 &0 \
0 &0 &0 &0 &0
end{bmatrix}

begin{bmatrix}
0 &0 &0 &0 &0 \
0 &0 &0 &0 &0 \
0 &0 &0 &1 &5\
0 &0 &2 &0 &0 \
0 &0 &7 &0 &0end{bmatrix}










share|cite|improve this question











$endgroup$












  • $begingroup$
    Any matrix $A$ is already trivially block-diagonal in the sense that it can be written $[A]$. You might need to constrain your question further.
    $endgroup$
    – parsiad
    Dec 2 '18 at 22:30










  • $begingroup$
    @parsiad, I thought the example made it clear that I'm talking about more than one block. Otherwise suggest how I should clarify my question please.
    $endgroup$
    – gciriani
    Dec 2 '18 at 22:47










  • $begingroup$
    You could specify a minimum number of blocks or an exact number of blocks to make the problem nontrivial.
    $endgroup$
    – parsiad
    Dec 2 '18 at 23:54






  • 1




    $begingroup$
    @parsiad, I added in the first paragraph "more than one block". I hope that helps.
    $endgroup$
    – gciriani
    Dec 3 '18 at 0:38










  • $begingroup$
    BTW, your first example is incorrect (it is actually not permutation similar to a matrix with two block diagonals). I think you dropped one of the nonzero elements (namely, the number 2 appears twice before you permute and only once afterwards)
    $endgroup$
    – parsiad
    Dec 3 '18 at 1:29


















2












$begingroup$


Is there a way to determine if by permutation of rows and columns a matrix can be transformed into a block-diagonal matrix (EDIT: with more than one block)? For example the following matrix



begin{bmatrix}
0 &0 &7 &0 &0 \
0 &0 &0 &0 &3 \
5 &0 &0 &1 &0\
0 &0 &2 &0 &0 \
0 &1 &0 &0 &0
end{bmatrix}

EDIT: set to 0 element in 2nd row that was =2.



By permuting first row with last row and first column with last column can be transformed into the following block-diagonal matrix.
begin{bmatrix}
0 &1 &0 &0 &0 \
3 &0 &0 &0 &0 \
0 &0 &0 &1 &5\
0 &0 &2 &0 &0 \
0 &0 &7 &0 &0
end{bmatrix}

Is there an algorithm to find out if it is possible and do it, or to determine the permutation matrix?



My problem is about representing points scored by players against each other in. I need to determine the relative strength of players by comparing their scores. Imagine the matrix is the score of a player against another player. Each row is a player, and each column is a player. The diagonal is empty, or zero. If nobody in a group of player has played against anybody in the other group of players, then I cannot rank one group against the other group, because I do not know their relative strength. So I'm trying to eventually decompose the matrix into several if they exist. In the example above they would be the two following ones
begin{bmatrix}
0 &1 &0 &0 &0 \
3 &0 &0 &0 &0 \
0 &0 &0 &0 &0\
0 &0 &0 &0 &0 \
0 &0 &0 &0 &0
end{bmatrix}

begin{bmatrix}
0 &0 &0 &0 &0 \
0 &0 &0 &0 &0 \
0 &0 &0 &1 &5\
0 &0 &2 &0 &0 \
0 &0 &7 &0 &0end{bmatrix}










share|cite|improve this question











$endgroup$












  • $begingroup$
    Any matrix $A$ is already trivially block-diagonal in the sense that it can be written $[A]$. You might need to constrain your question further.
    $endgroup$
    – parsiad
    Dec 2 '18 at 22:30










  • $begingroup$
    @parsiad, I thought the example made it clear that I'm talking about more than one block. Otherwise suggest how I should clarify my question please.
    $endgroup$
    – gciriani
    Dec 2 '18 at 22:47










  • $begingroup$
    You could specify a minimum number of blocks or an exact number of blocks to make the problem nontrivial.
    $endgroup$
    – parsiad
    Dec 2 '18 at 23:54






  • 1




    $begingroup$
    @parsiad, I added in the first paragraph "more than one block". I hope that helps.
    $endgroup$
    – gciriani
    Dec 3 '18 at 0:38










  • $begingroup$
    BTW, your first example is incorrect (it is actually not permutation similar to a matrix with two block diagonals). I think you dropped one of the nonzero elements (namely, the number 2 appears twice before you permute and only once afterwards)
    $endgroup$
    – parsiad
    Dec 3 '18 at 1:29
















2












2








2


1



$begingroup$


Is there a way to determine if by permutation of rows and columns a matrix can be transformed into a block-diagonal matrix (EDIT: with more than one block)? For example the following matrix



begin{bmatrix}
0 &0 &7 &0 &0 \
0 &0 &0 &0 &3 \
5 &0 &0 &1 &0\
0 &0 &2 &0 &0 \
0 &1 &0 &0 &0
end{bmatrix}

EDIT: set to 0 element in 2nd row that was =2.



By permuting first row with last row and first column with last column can be transformed into the following block-diagonal matrix.
begin{bmatrix}
0 &1 &0 &0 &0 \
3 &0 &0 &0 &0 \
0 &0 &0 &1 &5\
0 &0 &2 &0 &0 \
0 &0 &7 &0 &0
end{bmatrix}

Is there an algorithm to find out if it is possible and do it, or to determine the permutation matrix?



My problem is about representing points scored by players against each other in. I need to determine the relative strength of players by comparing their scores. Imagine the matrix is the score of a player against another player. Each row is a player, and each column is a player. The diagonal is empty, or zero. If nobody in a group of player has played against anybody in the other group of players, then I cannot rank one group against the other group, because I do not know their relative strength. So I'm trying to eventually decompose the matrix into several if they exist. In the example above they would be the two following ones
begin{bmatrix}
0 &1 &0 &0 &0 \
3 &0 &0 &0 &0 \
0 &0 &0 &0 &0\
0 &0 &0 &0 &0 \
0 &0 &0 &0 &0
end{bmatrix}

begin{bmatrix}
0 &0 &0 &0 &0 \
0 &0 &0 &0 &0 \
0 &0 &0 &1 &5\
0 &0 &2 &0 &0 \
0 &0 &7 &0 &0end{bmatrix}










share|cite|improve this question











$endgroup$




Is there a way to determine if by permutation of rows and columns a matrix can be transformed into a block-diagonal matrix (EDIT: with more than one block)? For example the following matrix



begin{bmatrix}
0 &0 &7 &0 &0 \
0 &0 &0 &0 &3 \
5 &0 &0 &1 &0\
0 &0 &2 &0 &0 \
0 &1 &0 &0 &0
end{bmatrix}

EDIT: set to 0 element in 2nd row that was =2.



By permuting first row with last row and first column with last column can be transformed into the following block-diagonal matrix.
begin{bmatrix}
0 &1 &0 &0 &0 \
3 &0 &0 &0 &0 \
0 &0 &0 &1 &5\
0 &0 &2 &0 &0 \
0 &0 &7 &0 &0
end{bmatrix}

Is there an algorithm to find out if it is possible and do it, or to determine the permutation matrix?



My problem is about representing points scored by players against each other in. I need to determine the relative strength of players by comparing their scores. Imagine the matrix is the score of a player against another player. Each row is a player, and each column is a player. The diagonal is empty, or zero. If nobody in a group of player has played against anybody in the other group of players, then I cannot rank one group against the other group, because I do not know their relative strength. So I'm trying to eventually decompose the matrix into several if they exist. In the example above they would be the two following ones
begin{bmatrix}
0 &1 &0 &0 &0 \
3 &0 &0 &0 &0 \
0 &0 &0 &0 &0\
0 &0 &0 &0 &0 \
0 &0 &0 &0 &0
end{bmatrix}

begin{bmatrix}
0 &0 &0 &0 &0 \
0 &0 &0 &0 &0 \
0 &0 &0 &1 &5\
0 &0 &2 &0 &0 \
0 &0 &7 &0 &0end{bmatrix}







diagonalization matrix-decomposition block-matrices






share|cite|improve this question















share|cite|improve this question













share|cite|improve this question




share|cite|improve this question








edited Dec 3 '18 at 3:13







gciriani

















asked Dec 2 '18 at 21:59









gcirianigciriani

275




275












  • $begingroup$
    Any matrix $A$ is already trivially block-diagonal in the sense that it can be written $[A]$. You might need to constrain your question further.
    $endgroup$
    – parsiad
    Dec 2 '18 at 22:30










  • $begingroup$
    @parsiad, I thought the example made it clear that I'm talking about more than one block. Otherwise suggest how I should clarify my question please.
    $endgroup$
    – gciriani
    Dec 2 '18 at 22:47










  • $begingroup$
    You could specify a minimum number of blocks or an exact number of blocks to make the problem nontrivial.
    $endgroup$
    – parsiad
    Dec 2 '18 at 23:54






  • 1




    $begingroup$
    @parsiad, I added in the first paragraph "more than one block". I hope that helps.
    $endgroup$
    – gciriani
    Dec 3 '18 at 0:38










  • $begingroup$
    BTW, your first example is incorrect (it is actually not permutation similar to a matrix with two block diagonals). I think you dropped one of the nonzero elements (namely, the number 2 appears twice before you permute and only once afterwards)
    $endgroup$
    – parsiad
    Dec 3 '18 at 1:29




















  • $begingroup$
    Any matrix $A$ is already trivially block-diagonal in the sense that it can be written $[A]$. You might need to constrain your question further.
    $endgroup$
    – parsiad
    Dec 2 '18 at 22:30










  • $begingroup$
    @parsiad, I thought the example made it clear that I'm talking about more than one block. Otherwise suggest how I should clarify my question please.
    $endgroup$
    – gciriani
    Dec 2 '18 at 22:47










  • $begingroup$
    You could specify a minimum number of blocks or an exact number of blocks to make the problem nontrivial.
    $endgroup$
    – parsiad
    Dec 2 '18 at 23:54






  • 1




    $begingroup$
    @parsiad, I added in the first paragraph "more than one block". I hope that helps.
    $endgroup$
    – gciriani
    Dec 3 '18 at 0:38










  • $begingroup$
    BTW, your first example is incorrect (it is actually not permutation similar to a matrix with two block diagonals). I think you dropped one of the nonzero elements (namely, the number 2 appears twice before you permute and only once afterwards)
    $endgroup$
    – parsiad
    Dec 3 '18 at 1:29


















$begingroup$
Any matrix $A$ is already trivially block-diagonal in the sense that it can be written $[A]$. You might need to constrain your question further.
$endgroup$
– parsiad
Dec 2 '18 at 22:30




$begingroup$
Any matrix $A$ is already trivially block-diagonal in the sense that it can be written $[A]$. You might need to constrain your question further.
$endgroup$
– parsiad
Dec 2 '18 at 22:30












$begingroup$
@parsiad, I thought the example made it clear that I'm talking about more than one block. Otherwise suggest how I should clarify my question please.
$endgroup$
– gciriani
Dec 2 '18 at 22:47




$begingroup$
@parsiad, I thought the example made it clear that I'm talking about more than one block. Otherwise suggest how I should clarify my question please.
$endgroup$
– gciriani
Dec 2 '18 at 22:47












$begingroup$
You could specify a minimum number of blocks or an exact number of blocks to make the problem nontrivial.
$endgroup$
– parsiad
Dec 2 '18 at 23:54




$begingroup$
You could specify a minimum number of blocks or an exact number of blocks to make the problem nontrivial.
$endgroup$
– parsiad
Dec 2 '18 at 23:54




1




1




$begingroup$
@parsiad, I added in the first paragraph "more than one block". I hope that helps.
$endgroup$
– gciriani
Dec 3 '18 at 0:38




$begingroup$
@parsiad, I added in the first paragraph "more than one block". I hope that helps.
$endgroup$
– gciriani
Dec 3 '18 at 0:38












$begingroup$
BTW, your first example is incorrect (it is actually not permutation similar to a matrix with two block diagonals). I think you dropped one of the nonzero elements (namely, the number 2 appears twice before you permute and only once afterwards)
$endgroup$
– parsiad
Dec 3 '18 at 1:29






$begingroup$
BTW, your first example is incorrect (it is actually not permutation similar to a matrix with two block diagonals). I think you dropped one of the nonzero elements (namely, the number 2 appears twice before you permute and only once afterwards)
$endgroup$
– parsiad
Dec 3 '18 at 1:29












2 Answers
2






active

oldest

votes


















2












$begingroup$

Problem



Given an $ntimes n$ matrix $A=(a_{ij})$, determine if it is possible to find a permutation matrix $P=(p_{ij})$ and square matrices $B$ and $C$ such that
$$
PAP^{intercal}=begin{pmatrix}B & 0\
0 & C
end{pmatrix}.
$$



Note: By grouping blocks, any matrix with three or more diagonal blocks can also be considered as a matrix with two diagonal blocks. For example,



$$
begin{pmatrix}B\
& C\
& & D
end{pmatrix}=begin{pmatrix}B\
& begin{pmatrix}C\
& D
end{pmatrix}
end{pmatrix}
$$



Solution



Let $G=(V,E)$ denote the undirected adjacency graph of $A$.
That is, $V$ and $E$ are defined by
$$
V={1,ldots,n}qquadtext{and}qquad E=left{ (i,j)in Vtimes Vcolon a_{ij}neq0text{ or }a_{ji}neq0right}.
$$

Now, our original problem is equivalent to determining whether $G$ is a graph with two or more disjoint components.



This is accomplished with a breadth-first search (or depth-first search) started at an arbitrary vertex, call it $v_{1}$.
Let $V^{prime}={v_{1},ldots,v_{k}}$ be the set of vertices visited by the search.
Then, the answer to our original problem is in the affirmitive if and only if $V^{prime}$ is a proper subset of $V$.



Example



Let's apply the algorithm to the matrix
$$
A=begin{pmatrix}0 & 0 & 7 & 0 & 0\
0 & 0 & 0 & 0 & 3\
5 & 0 & 0 & 1 & 0\
0 & 0 & 2 & 0 & 0\
0 & 1 & 0 & 0 & 0
end{pmatrix}.
$$



Let's run the search algorithm:




  • Pick $v_{1}=1$ corresponding to the first row.

  • The only nonzero entry in this row is $a_{v_{1}3} = 7$ so we pick $v_{2}=3$ as the next row to visit.

  • The only nonzero entries in this row are $a_{v_{2}1} = 5$ and $a_{v_{2}4} = 1$. We have already visited the first row so we pick $v_{3}=4$ as the next row to visit.

  • The only nonzero entry in this row is $a_{v_{3} 3} = 2$. We have already visited the third row and hence the search terminates.


The final vertex set is $V^{prime}={v_1,v_2,v_3}={1,3,4}$.
Next, make any permutation matrix that satisfies $p_{1v_{1}}=p_{2v_{2}}=p_{3v_{3}}=1$.
For example, we could take
$$
P=begin{pmatrix}1 & 0 & 0 & 0 & 0\
0 & 0 & 1 & 0 & 0\
0 & 0 & 0 & 1 & 0\
0 & 1 & 0 & 0 & 0\
0 & 0 & 0 & 0 & 1
end{pmatrix}.
$$

You can check that $PAP^{intercal}$ has two diagonal blocks:
$$
PAP^{intercal}=begin{pmatrix}0 & 7 & 0 & 0 & 0\
5 & 0 & 1 & 0 & 0\
0 & 2 & 0 & 0 & 0\
0 & 0 & 0 & 0 & 3\
0 & 0 & 0 & 1 & 0
end{pmatrix}.
$$



MATLAB implementation



The code below can be used to make the matrix P described above from an input matrix A. Just call perm_mat_to_make_block_diag(A).



Note: I don't have access to MATLAB and GNU Octave has not implemented the breadth-first search function bfsearch, so I was unable to test the code below. If someone could test it for me, that would be great.



function P = perm_mat_to_make_block_diag(A)
% Make the undirected adjacency graph for A.
nonzero = A != 0;
adjacency = nonzero + nonzero';
G = graph(A);

% Perform breadth-first search.
v_1 = 1;
V_prime = bfsearch(G, v_1);
n = length(A);
if length(V_prime) == n
error('Input is not permutation-similar to a block-diagonal matrix.');
end

% Make the permutation matrix.
i = (1:n)';
V_prime_complement = setdiff(i, V_prime);
j = [V_prime; V_prime_complement];
P = sparse(i, j, ones(n, 1), n, n);
end





share|cite|improve this answer











$endgroup$













  • $begingroup$
    Is there an easy way to implement this in Matlab or Octave?
    $endgroup$
    – gciriani
    Dec 3 '18 at 2:54












  • $begingroup$
    do you know how to extract the blocks?
    $endgroup$
    – gciriani
    Dec 3 '18 at 16:02










  • $begingroup$
    To your first question, I just added a MATLAB implementation. To your second question, the two blocks are given by the indices in $V^prime$ and $(V^prime)^{complement} equiv V setminus V^prime$ (these are called V_prime and V_prime_complement in the MATLAB code).
    $endgroup$
    – parsiad
    Dec 4 '18 at 1:44












  • $begingroup$
    Unfortunately I do not have Matlab, and use only Octave, so I cannot test your code either. However, I found an easy implementation, inspired by Calvin-Lin @MISC {277075, TITLE = {Easiest way to determine all disconnected sets from a graph?}, AUTHOR = {Calvin Lin (math.stackexchange.com/users/54563/calvin-lin)}, HOWPUBLISHED = {Mathematics Stack Exchange}, NOTE = {URL:math.stackexchange.com/q/277075 (version: 2013-01-13)}, EPRINT = {math.stackexchange.com/q/277075}, URL = {math.stackexchange.com/q/277075} }
    $endgroup$
    – gciriani
    Dec 4 '18 at 19:34










  • $begingroup$
    ...continued. If A is the connection matrix, then C=((A>0) + I)^n where n is the size of the matrix, transforms it in a matrix with all possible paths of length n, which are identical for connected nodes, and different for each disconnected graph. Then with the command [Y,i,j]=Unique(C, 'rows') I obtain the different connection blocks and their respective positions.
    $endgroup$
    – gciriani
    Dec 4 '18 at 19:49



















1












$begingroup$

The Dulmage-Mendelsohn decomposition (dmperm in MATLAB) can be used to do this for symmetric matrices (or just turn your non-symmetric matrix into a matrix of 0's and 1's with 1's replacing all non-zero entries in the original matrix.)






share|cite|improve this answer









$endgroup$













  • $begingroup$
    I tried dmperm, but it doesn't seem to perform what I'm trying to determine. According to Octave's help, dmperm is used for block triangular form, which is not what I'm trying to accomplish. What I need is to determine the disjoint components.
    $endgroup$
    – gciriani
    Dec 3 '18 at 13:38










  • $begingroup$
    If your original matrix is symmetric, then p=dmperm(A), B=A(p,p) will put the matrix into block upper triangular form, but since the matrix is symmetric, that will also be block diagonal form. Try it.
    $endgroup$
    – Brian Borchers
    Dec 3 '18 at 15:02










  • $begingroup$
    one of the elements of p turns out to be 0, and dmperm gives an error; my example [0 0 5 1 0; 0 0 0 0 3; 7 0 0 0 0; 2 0 0 0 0; 0 1 0 0 0]
    $endgroup$
    – gciriani
    Dec 3 '18 at 16:42












  • $begingroup$
    Your example matrix isn't symmetric.
    $endgroup$
    – Brian Borchers
    Dec 3 '18 at 16:47










  • $begingroup$
    Even with a symmetric matrix [0 0 1 1 0; 0 0 0 0 1; 1 0 0 0 0; 1 0 0 0 0; 0 1 0 0 0], dmperm gives [3, 5, 1, 0, 2] as a result.
    $endgroup$
    – gciriani
    Dec 4 '18 at 14:56











Your Answer





StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "69"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3023268%2fdetermine-if-matrix-can-be-permutated-into-block-diagonal-matrix%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









2












$begingroup$

Problem



Given an $ntimes n$ matrix $A=(a_{ij})$, determine if it is possible to find a permutation matrix $P=(p_{ij})$ and square matrices $B$ and $C$ such that
$$
PAP^{intercal}=begin{pmatrix}B & 0\
0 & C
end{pmatrix}.
$$



Note: By grouping blocks, any matrix with three or more diagonal blocks can also be considered as a matrix with two diagonal blocks. For example,



$$
begin{pmatrix}B\
& C\
& & D
end{pmatrix}=begin{pmatrix}B\
& begin{pmatrix}C\
& D
end{pmatrix}
end{pmatrix}
$$



Solution



Let $G=(V,E)$ denote the undirected adjacency graph of $A$.
That is, $V$ and $E$ are defined by
$$
V={1,ldots,n}qquadtext{and}qquad E=left{ (i,j)in Vtimes Vcolon a_{ij}neq0text{ or }a_{ji}neq0right}.
$$

Now, our original problem is equivalent to determining whether $G$ is a graph with two or more disjoint components.



This is accomplished with a breadth-first search (or depth-first search) started at an arbitrary vertex, call it $v_{1}$.
Let $V^{prime}={v_{1},ldots,v_{k}}$ be the set of vertices visited by the search.
Then, the answer to our original problem is in the affirmitive if and only if $V^{prime}$ is a proper subset of $V$.



Example



Let's apply the algorithm to the matrix
$$
A=begin{pmatrix}0 & 0 & 7 & 0 & 0\
0 & 0 & 0 & 0 & 3\
5 & 0 & 0 & 1 & 0\
0 & 0 & 2 & 0 & 0\
0 & 1 & 0 & 0 & 0
end{pmatrix}.
$$



Let's run the search algorithm:




  • Pick $v_{1}=1$ corresponding to the first row.

  • The only nonzero entry in this row is $a_{v_{1}3} = 7$ so we pick $v_{2}=3$ as the next row to visit.

  • The only nonzero entries in this row are $a_{v_{2}1} = 5$ and $a_{v_{2}4} = 1$. We have already visited the first row so we pick $v_{3}=4$ as the next row to visit.

  • The only nonzero entry in this row is $a_{v_{3} 3} = 2$. We have already visited the third row and hence the search terminates.


The final vertex set is $V^{prime}={v_1,v_2,v_3}={1,3,4}$.
Next, make any permutation matrix that satisfies $p_{1v_{1}}=p_{2v_{2}}=p_{3v_{3}}=1$.
For example, we could take
$$
P=begin{pmatrix}1 & 0 & 0 & 0 & 0\
0 & 0 & 1 & 0 & 0\
0 & 0 & 0 & 1 & 0\
0 & 1 & 0 & 0 & 0\
0 & 0 & 0 & 0 & 1
end{pmatrix}.
$$

You can check that $PAP^{intercal}$ has two diagonal blocks:
$$
PAP^{intercal}=begin{pmatrix}0 & 7 & 0 & 0 & 0\
5 & 0 & 1 & 0 & 0\
0 & 2 & 0 & 0 & 0\
0 & 0 & 0 & 0 & 3\
0 & 0 & 0 & 1 & 0
end{pmatrix}.
$$



MATLAB implementation



The code below can be used to make the matrix P described above from an input matrix A. Just call perm_mat_to_make_block_diag(A).



Note: I don't have access to MATLAB and GNU Octave has not implemented the breadth-first search function bfsearch, so I was unable to test the code below. If someone could test it for me, that would be great.



function P = perm_mat_to_make_block_diag(A)
% Make the undirected adjacency graph for A.
nonzero = A != 0;
adjacency = nonzero + nonzero';
G = graph(A);

% Perform breadth-first search.
v_1 = 1;
V_prime = bfsearch(G, v_1);
n = length(A);
if length(V_prime) == n
error('Input is not permutation-similar to a block-diagonal matrix.');
end

% Make the permutation matrix.
i = (1:n)';
V_prime_complement = setdiff(i, V_prime);
j = [V_prime; V_prime_complement];
P = sparse(i, j, ones(n, 1), n, n);
end





share|cite|improve this answer











$endgroup$













  • $begingroup$
    Is there an easy way to implement this in Matlab or Octave?
    $endgroup$
    – gciriani
    Dec 3 '18 at 2:54












  • $begingroup$
    do you know how to extract the blocks?
    $endgroup$
    – gciriani
    Dec 3 '18 at 16:02










  • $begingroup$
    To your first question, I just added a MATLAB implementation. To your second question, the two blocks are given by the indices in $V^prime$ and $(V^prime)^{complement} equiv V setminus V^prime$ (these are called V_prime and V_prime_complement in the MATLAB code).
    $endgroup$
    – parsiad
    Dec 4 '18 at 1:44












  • $begingroup$
    Unfortunately I do not have Matlab, and use only Octave, so I cannot test your code either. However, I found an easy implementation, inspired by Calvin-Lin @MISC {277075, TITLE = {Easiest way to determine all disconnected sets from a graph?}, AUTHOR = {Calvin Lin (math.stackexchange.com/users/54563/calvin-lin)}, HOWPUBLISHED = {Mathematics Stack Exchange}, NOTE = {URL:math.stackexchange.com/q/277075 (version: 2013-01-13)}, EPRINT = {math.stackexchange.com/q/277075}, URL = {math.stackexchange.com/q/277075} }
    $endgroup$
    – gciriani
    Dec 4 '18 at 19:34










  • $begingroup$
    ...continued. If A is the connection matrix, then C=((A>0) + I)^n where n is the size of the matrix, transforms it in a matrix with all possible paths of length n, which are identical for connected nodes, and different for each disconnected graph. Then with the command [Y,i,j]=Unique(C, 'rows') I obtain the different connection blocks and their respective positions.
    $endgroup$
    – gciriani
    Dec 4 '18 at 19:49
















2












$begingroup$

Problem



Given an $ntimes n$ matrix $A=(a_{ij})$, determine if it is possible to find a permutation matrix $P=(p_{ij})$ and square matrices $B$ and $C$ such that
$$
PAP^{intercal}=begin{pmatrix}B & 0\
0 & C
end{pmatrix}.
$$



Note: By grouping blocks, any matrix with three or more diagonal blocks can also be considered as a matrix with two diagonal blocks. For example,



$$
begin{pmatrix}B\
& C\
& & D
end{pmatrix}=begin{pmatrix}B\
& begin{pmatrix}C\
& D
end{pmatrix}
end{pmatrix}
$$



Solution



Let $G=(V,E)$ denote the undirected adjacency graph of $A$.
That is, $V$ and $E$ are defined by
$$
V={1,ldots,n}qquadtext{and}qquad E=left{ (i,j)in Vtimes Vcolon a_{ij}neq0text{ or }a_{ji}neq0right}.
$$

Now, our original problem is equivalent to determining whether $G$ is a graph with two or more disjoint components.



This is accomplished with a breadth-first search (or depth-first search) started at an arbitrary vertex, call it $v_{1}$.
Let $V^{prime}={v_{1},ldots,v_{k}}$ be the set of vertices visited by the search.
Then, the answer to our original problem is in the affirmitive if and only if $V^{prime}$ is a proper subset of $V$.



Example



Let's apply the algorithm to the matrix
$$
A=begin{pmatrix}0 & 0 & 7 & 0 & 0\
0 & 0 & 0 & 0 & 3\
5 & 0 & 0 & 1 & 0\
0 & 0 & 2 & 0 & 0\
0 & 1 & 0 & 0 & 0
end{pmatrix}.
$$



Let's run the search algorithm:




  • Pick $v_{1}=1$ corresponding to the first row.

  • The only nonzero entry in this row is $a_{v_{1}3} = 7$ so we pick $v_{2}=3$ as the next row to visit.

  • The only nonzero entries in this row are $a_{v_{2}1} = 5$ and $a_{v_{2}4} = 1$. We have already visited the first row so we pick $v_{3}=4$ as the next row to visit.

  • The only nonzero entry in this row is $a_{v_{3} 3} = 2$. We have already visited the third row and hence the search terminates.


The final vertex set is $V^{prime}={v_1,v_2,v_3}={1,3,4}$.
Next, make any permutation matrix that satisfies $p_{1v_{1}}=p_{2v_{2}}=p_{3v_{3}}=1$.
For example, we could take
$$
P=begin{pmatrix}1 & 0 & 0 & 0 & 0\
0 & 0 & 1 & 0 & 0\
0 & 0 & 0 & 1 & 0\
0 & 1 & 0 & 0 & 0\
0 & 0 & 0 & 0 & 1
end{pmatrix}.
$$

You can check that $PAP^{intercal}$ has two diagonal blocks:
$$
PAP^{intercal}=begin{pmatrix}0 & 7 & 0 & 0 & 0\
5 & 0 & 1 & 0 & 0\
0 & 2 & 0 & 0 & 0\
0 & 0 & 0 & 0 & 3\
0 & 0 & 0 & 1 & 0
end{pmatrix}.
$$



MATLAB implementation



The code below can be used to make the matrix P described above from an input matrix A. Just call perm_mat_to_make_block_diag(A).



Note: I don't have access to MATLAB and GNU Octave has not implemented the breadth-first search function bfsearch, so I was unable to test the code below. If someone could test it for me, that would be great.



function P = perm_mat_to_make_block_diag(A)
% Make the undirected adjacency graph for A.
nonzero = A != 0;
adjacency = nonzero + nonzero';
G = graph(A);

% Perform breadth-first search.
v_1 = 1;
V_prime = bfsearch(G, v_1);
n = length(A);
if length(V_prime) == n
error('Input is not permutation-similar to a block-diagonal matrix.');
end

% Make the permutation matrix.
i = (1:n)';
V_prime_complement = setdiff(i, V_prime);
j = [V_prime; V_prime_complement];
P = sparse(i, j, ones(n, 1), n, n);
end





share|cite|improve this answer











$endgroup$













  • $begingroup$
    Is there an easy way to implement this in Matlab or Octave?
    $endgroup$
    – gciriani
    Dec 3 '18 at 2:54












  • $begingroup$
    do you know how to extract the blocks?
    $endgroup$
    – gciriani
    Dec 3 '18 at 16:02










  • $begingroup$
    To your first question, I just added a MATLAB implementation. To your second question, the two blocks are given by the indices in $V^prime$ and $(V^prime)^{complement} equiv V setminus V^prime$ (these are called V_prime and V_prime_complement in the MATLAB code).
    $endgroup$
    – parsiad
    Dec 4 '18 at 1:44












  • $begingroup$
    Unfortunately I do not have Matlab, and use only Octave, so I cannot test your code either. However, I found an easy implementation, inspired by Calvin-Lin @MISC {277075, TITLE = {Easiest way to determine all disconnected sets from a graph?}, AUTHOR = {Calvin Lin (math.stackexchange.com/users/54563/calvin-lin)}, HOWPUBLISHED = {Mathematics Stack Exchange}, NOTE = {URL:math.stackexchange.com/q/277075 (version: 2013-01-13)}, EPRINT = {math.stackexchange.com/q/277075}, URL = {math.stackexchange.com/q/277075} }
    $endgroup$
    – gciriani
    Dec 4 '18 at 19:34










  • $begingroup$
    ...continued. If A is the connection matrix, then C=((A>0) + I)^n where n is the size of the matrix, transforms it in a matrix with all possible paths of length n, which are identical for connected nodes, and different for each disconnected graph. Then with the command [Y,i,j]=Unique(C, 'rows') I obtain the different connection blocks and their respective positions.
    $endgroup$
    – gciriani
    Dec 4 '18 at 19:49














2












2








2





$begingroup$

Problem



Given an $ntimes n$ matrix $A=(a_{ij})$, determine if it is possible to find a permutation matrix $P=(p_{ij})$ and square matrices $B$ and $C$ such that
$$
PAP^{intercal}=begin{pmatrix}B & 0\
0 & C
end{pmatrix}.
$$



Note: By grouping blocks, any matrix with three or more diagonal blocks can also be considered as a matrix with two diagonal blocks. For example,



$$
begin{pmatrix}B\
& C\
& & D
end{pmatrix}=begin{pmatrix}B\
& begin{pmatrix}C\
& D
end{pmatrix}
end{pmatrix}
$$



Solution



Let $G=(V,E)$ denote the undirected adjacency graph of $A$.
That is, $V$ and $E$ are defined by
$$
V={1,ldots,n}qquadtext{and}qquad E=left{ (i,j)in Vtimes Vcolon a_{ij}neq0text{ or }a_{ji}neq0right}.
$$

Now, our original problem is equivalent to determining whether $G$ is a graph with two or more disjoint components.



This is accomplished with a breadth-first search (or depth-first search) started at an arbitrary vertex, call it $v_{1}$.
Let $V^{prime}={v_{1},ldots,v_{k}}$ be the set of vertices visited by the search.
Then, the answer to our original problem is in the affirmitive if and only if $V^{prime}$ is a proper subset of $V$.



Example



Let's apply the algorithm to the matrix
$$
A=begin{pmatrix}0 & 0 & 7 & 0 & 0\
0 & 0 & 0 & 0 & 3\
5 & 0 & 0 & 1 & 0\
0 & 0 & 2 & 0 & 0\
0 & 1 & 0 & 0 & 0
end{pmatrix}.
$$



Let's run the search algorithm:




  • Pick $v_{1}=1$ corresponding to the first row.

  • The only nonzero entry in this row is $a_{v_{1}3} = 7$ so we pick $v_{2}=3$ as the next row to visit.

  • The only nonzero entries in this row are $a_{v_{2}1} = 5$ and $a_{v_{2}4} = 1$. We have already visited the first row so we pick $v_{3}=4$ as the next row to visit.

  • The only nonzero entry in this row is $a_{v_{3} 3} = 2$. We have already visited the third row and hence the search terminates.


The final vertex set is $V^{prime}={v_1,v_2,v_3}={1,3,4}$.
Next, make any permutation matrix that satisfies $p_{1v_{1}}=p_{2v_{2}}=p_{3v_{3}}=1$.
For example, we could take
$$
P=begin{pmatrix}1 & 0 & 0 & 0 & 0\
0 & 0 & 1 & 0 & 0\
0 & 0 & 0 & 1 & 0\
0 & 1 & 0 & 0 & 0\
0 & 0 & 0 & 0 & 1
end{pmatrix}.
$$

You can check that $PAP^{intercal}$ has two diagonal blocks:
$$
PAP^{intercal}=begin{pmatrix}0 & 7 & 0 & 0 & 0\
5 & 0 & 1 & 0 & 0\
0 & 2 & 0 & 0 & 0\
0 & 0 & 0 & 0 & 3\
0 & 0 & 0 & 1 & 0
end{pmatrix}.
$$



MATLAB implementation



The code below can be used to make the matrix P described above from an input matrix A. Just call perm_mat_to_make_block_diag(A).



Note: I don't have access to MATLAB and GNU Octave has not implemented the breadth-first search function bfsearch, so I was unable to test the code below. If someone could test it for me, that would be great.



function P = perm_mat_to_make_block_diag(A)
% Make the undirected adjacency graph for A.
nonzero = A != 0;
adjacency = nonzero + nonzero';
G = graph(A);

% Perform breadth-first search.
v_1 = 1;
V_prime = bfsearch(G, v_1);
n = length(A);
if length(V_prime) == n
error('Input is not permutation-similar to a block-diagonal matrix.');
end

% Make the permutation matrix.
i = (1:n)';
V_prime_complement = setdiff(i, V_prime);
j = [V_prime; V_prime_complement];
P = sparse(i, j, ones(n, 1), n, n);
end





share|cite|improve this answer











$endgroup$



Problem



Given an $ntimes n$ matrix $A=(a_{ij})$, determine if it is possible to find a permutation matrix $P=(p_{ij})$ and square matrices $B$ and $C$ such that
$$
PAP^{intercal}=begin{pmatrix}B & 0\
0 & C
end{pmatrix}.
$$



Note: By grouping blocks, any matrix with three or more diagonal blocks can also be considered as a matrix with two diagonal blocks. For example,



$$
begin{pmatrix}B\
& C\
& & D
end{pmatrix}=begin{pmatrix}B\
& begin{pmatrix}C\
& D
end{pmatrix}
end{pmatrix}
$$



Solution



Let $G=(V,E)$ denote the undirected adjacency graph of $A$.
That is, $V$ and $E$ are defined by
$$
V={1,ldots,n}qquadtext{and}qquad E=left{ (i,j)in Vtimes Vcolon a_{ij}neq0text{ or }a_{ji}neq0right}.
$$

Now, our original problem is equivalent to determining whether $G$ is a graph with two or more disjoint components.



This is accomplished with a breadth-first search (or depth-first search) started at an arbitrary vertex, call it $v_{1}$.
Let $V^{prime}={v_{1},ldots,v_{k}}$ be the set of vertices visited by the search.
Then, the answer to our original problem is in the affirmitive if and only if $V^{prime}$ is a proper subset of $V$.



Example



Let's apply the algorithm to the matrix
$$
A=begin{pmatrix}0 & 0 & 7 & 0 & 0\
0 & 0 & 0 & 0 & 3\
5 & 0 & 0 & 1 & 0\
0 & 0 & 2 & 0 & 0\
0 & 1 & 0 & 0 & 0
end{pmatrix}.
$$



Let's run the search algorithm:




  • Pick $v_{1}=1$ corresponding to the first row.

  • The only nonzero entry in this row is $a_{v_{1}3} = 7$ so we pick $v_{2}=3$ as the next row to visit.

  • The only nonzero entries in this row are $a_{v_{2}1} = 5$ and $a_{v_{2}4} = 1$. We have already visited the first row so we pick $v_{3}=4$ as the next row to visit.

  • The only nonzero entry in this row is $a_{v_{3} 3} = 2$. We have already visited the third row and hence the search terminates.


The final vertex set is $V^{prime}={v_1,v_2,v_3}={1,3,4}$.
Next, make any permutation matrix that satisfies $p_{1v_{1}}=p_{2v_{2}}=p_{3v_{3}}=1$.
For example, we could take
$$
P=begin{pmatrix}1 & 0 & 0 & 0 & 0\
0 & 0 & 1 & 0 & 0\
0 & 0 & 0 & 1 & 0\
0 & 1 & 0 & 0 & 0\
0 & 0 & 0 & 0 & 1
end{pmatrix}.
$$

You can check that $PAP^{intercal}$ has two diagonal blocks:
$$
PAP^{intercal}=begin{pmatrix}0 & 7 & 0 & 0 & 0\
5 & 0 & 1 & 0 & 0\
0 & 2 & 0 & 0 & 0\
0 & 0 & 0 & 0 & 3\
0 & 0 & 0 & 1 & 0
end{pmatrix}.
$$



MATLAB implementation



The code below can be used to make the matrix P described above from an input matrix A. Just call perm_mat_to_make_block_diag(A).



Note: I don't have access to MATLAB and GNU Octave has not implemented the breadth-first search function bfsearch, so I was unable to test the code below. If someone could test it for me, that would be great.



function P = perm_mat_to_make_block_diag(A)
% Make the undirected adjacency graph for A.
nonzero = A != 0;
adjacency = nonzero + nonzero';
G = graph(A);

% Perform breadth-first search.
v_1 = 1;
V_prime = bfsearch(G, v_1);
n = length(A);
if length(V_prime) == n
error('Input is not permutation-similar to a block-diagonal matrix.');
end

% Make the permutation matrix.
i = (1:n)';
V_prime_complement = setdiff(i, V_prime);
j = [V_prime; V_prime_complement];
P = sparse(i, j, ones(n, 1), n, n);
end






share|cite|improve this answer














share|cite|improve this answer



share|cite|improve this answer








edited Dec 4 '18 at 1:48

























answered Dec 3 '18 at 1:19









parsiadparsiad

17.8k32353




17.8k32353












  • $begingroup$
    Is there an easy way to implement this in Matlab or Octave?
    $endgroup$
    – gciriani
    Dec 3 '18 at 2:54












  • $begingroup$
    do you know how to extract the blocks?
    $endgroup$
    – gciriani
    Dec 3 '18 at 16:02










  • $begingroup$
    To your first question, I just added a MATLAB implementation. To your second question, the two blocks are given by the indices in $V^prime$ and $(V^prime)^{complement} equiv V setminus V^prime$ (these are called V_prime and V_prime_complement in the MATLAB code).
    $endgroup$
    – parsiad
    Dec 4 '18 at 1:44












  • $begingroup$
    Unfortunately I do not have Matlab, and use only Octave, so I cannot test your code either. However, I found an easy implementation, inspired by Calvin-Lin @MISC {277075, TITLE = {Easiest way to determine all disconnected sets from a graph?}, AUTHOR = {Calvin Lin (math.stackexchange.com/users/54563/calvin-lin)}, HOWPUBLISHED = {Mathematics Stack Exchange}, NOTE = {URL:math.stackexchange.com/q/277075 (version: 2013-01-13)}, EPRINT = {math.stackexchange.com/q/277075}, URL = {math.stackexchange.com/q/277075} }
    $endgroup$
    – gciriani
    Dec 4 '18 at 19:34










  • $begingroup$
    ...continued. If A is the connection matrix, then C=((A>0) + I)^n where n is the size of the matrix, transforms it in a matrix with all possible paths of length n, which are identical for connected nodes, and different for each disconnected graph. Then with the command [Y,i,j]=Unique(C, 'rows') I obtain the different connection blocks and their respective positions.
    $endgroup$
    – gciriani
    Dec 4 '18 at 19:49


















  • $begingroup$
    Is there an easy way to implement this in Matlab or Octave?
    $endgroup$
    – gciriani
    Dec 3 '18 at 2:54












  • $begingroup$
    do you know how to extract the blocks?
    $endgroup$
    – gciriani
    Dec 3 '18 at 16:02










  • $begingroup$
    To your first question, I just added a MATLAB implementation. To your second question, the two blocks are given by the indices in $V^prime$ and $(V^prime)^{complement} equiv V setminus V^prime$ (these are called V_prime and V_prime_complement in the MATLAB code).
    $endgroup$
    – parsiad
    Dec 4 '18 at 1:44












  • $begingroup$
    Unfortunately I do not have Matlab, and use only Octave, so I cannot test your code either. However, I found an easy implementation, inspired by Calvin-Lin @MISC {277075, TITLE = {Easiest way to determine all disconnected sets from a graph?}, AUTHOR = {Calvin Lin (math.stackexchange.com/users/54563/calvin-lin)}, HOWPUBLISHED = {Mathematics Stack Exchange}, NOTE = {URL:math.stackexchange.com/q/277075 (version: 2013-01-13)}, EPRINT = {math.stackexchange.com/q/277075}, URL = {math.stackexchange.com/q/277075} }
    $endgroup$
    – gciriani
    Dec 4 '18 at 19:34










  • $begingroup$
    ...continued. If A is the connection matrix, then C=((A>0) + I)^n where n is the size of the matrix, transforms it in a matrix with all possible paths of length n, which are identical for connected nodes, and different for each disconnected graph. Then with the command [Y,i,j]=Unique(C, 'rows') I obtain the different connection blocks and their respective positions.
    $endgroup$
    – gciriani
    Dec 4 '18 at 19:49
















$begingroup$
Is there an easy way to implement this in Matlab or Octave?
$endgroup$
– gciriani
Dec 3 '18 at 2:54






$begingroup$
Is there an easy way to implement this in Matlab or Octave?
$endgroup$
– gciriani
Dec 3 '18 at 2:54














$begingroup$
do you know how to extract the blocks?
$endgroup$
– gciriani
Dec 3 '18 at 16:02




$begingroup$
do you know how to extract the blocks?
$endgroup$
– gciriani
Dec 3 '18 at 16:02












$begingroup$
To your first question, I just added a MATLAB implementation. To your second question, the two blocks are given by the indices in $V^prime$ and $(V^prime)^{complement} equiv V setminus V^prime$ (these are called V_prime and V_prime_complement in the MATLAB code).
$endgroup$
– parsiad
Dec 4 '18 at 1:44






$begingroup$
To your first question, I just added a MATLAB implementation. To your second question, the two blocks are given by the indices in $V^prime$ and $(V^prime)^{complement} equiv V setminus V^prime$ (these are called V_prime and V_prime_complement in the MATLAB code).
$endgroup$
– parsiad
Dec 4 '18 at 1:44














$begingroup$
Unfortunately I do not have Matlab, and use only Octave, so I cannot test your code either. However, I found an easy implementation, inspired by Calvin-Lin @MISC {277075, TITLE = {Easiest way to determine all disconnected sets from a graph?}, AUTHOR = {Calvin Lin (math.stackexchange.com/users/54563/calvin-lin)}, HOWPUBLISHED = {Mathematics Stack Exchange}, NOTE = {URL:math.stackexchange.com/q/277075 (version: 2013-01-13)}, EPRINT = {math.stackexchange.com/q/277075}, URL = {math.stackexchange.com/q/277075} }
$endgroup$
– gciriani
Dec 4 '18 at 19:34




$begingroup$
Unfortunately I do not have Matlab, and use only Octave, so I cannot test your code either. However, I found an easy implementation, inspired by Calvin-Lin @MISC {277075, TITLE = {Easiest way to determine all disconnected sets from a graph?}, AUTHOR = {Calvin Lin (math.stackexchange.com/users/54563/calvin-lin)}, HOWPUBLISHED = {Mathematics Stack Exchange}, NOTE = {URL:math.stackexchange.com/q/277075 (version: 2013-01-13)}, EPRINT = {math.stackexchange.com/q/277075}, URL = {math.stackexchange.com/q/277075} }
$endgroup$
– gciriani
Dec 4 '18 at 19:34












$begingroup$
...continued. If A is the connection matrix, then C=((A>0) + I)^n where n is the size of the matrix, transforms it in a matrix with all possible paths of length n, which are identical for connected nodes, and different for each disconnected graph. Then with the command [Y,i,j]=Unique(C, 'rows') I obtain the different connection blocks and their respective positions.
$endgroup$
– gciriani
Dec 4 '18 at 19:49




$begingroup$
...continued. If A is the connection matrix, then C=((A>0) + I)^n where n is the size of the matrix, transforms it in a matrix with all possible paths of length n, which are identical for connected nodes, and different for each disconnected graph. Then with the command [Y,i,j]=Unique(C, 'rows') I obtain the different connection blocks and their respective positions.
$endgroup$
– gciriani
Dec 4 '18 at 19:49











1












$begingroup$

The Dulmage-Mendelsohn decomposition (dmperm in MATLAB) can be used to do this for symmetric matrices (or just turn your non-symmetric matrix into a matrix of 0's and 1's with 1's replacing all non-zero entries in the original matrix.)






share|cite|improve this answer









$endgroup$













  • $begingroup$
    I tried dmperm, but it doesn't seem to perform what I'm trying to determine. According to Octave's help, dmperm is used for block triangular form, which is not what I'm trying to accomplish. What I need is to determine the disjoint components.
    $endgroup$
    – gciriani
    Dec 3 '18 at 13:38










  • $begingroup$
    If your original matrix is symmetric, then p=dmperm(A), B=A(p,p) will put the matrix into block upper triangular form, but since the matrix is symmetric, that will also be block diagonal form. Try it.
    $endgroup$
    – Brian Borchers
    Dec 3 '18 at 15:02










  • $begingroup$
    one of the elements of p turns out to be 0, and dmperm gives an error; my example [0 0 5 1 0; 0 0 0 0 3; 7 0 0 0 0; 2 0 0 0 0; 0 1 0 0 0]
    $endgroup$
    – gciriani
    Dec 3 '18 at 16:42












  • $begingroup$
    Your example matrix isn't symmetric.
    $endgroup$
    – Brian Borchers
    Dec 3 '18 at 16:47










  • $begingroup$
    Even with a symmetric matrix [0 0 1 1 0; 0 0 0 0 1; 1 0 0 0 0; 1 0 0 0 0; 0 1 0 0 0], dmperm gives [3, 5, 1, 0, 2] as a result.
    $endgroup$
    – gciriani
    Dec 4 '18 at 14:56
















1












$begingroup$

The Dulmage-Mendelsohn decomposition (dmperm in MATLAB) can be used to do this for symmetric matrices (or just turn your non-symmetric matrix into a matrix of 0's and 1's with 1's replacing all non-zero entries in the original matrix.)






share|cite|improve this answer









$endgroup$













  • $begingroup$
    I tried dmperm, but it doesn't seem to perform what I'm trying to determine. According to Octave's help, dmperm is used for block triangular form, which is not what I'm trying to accomplish. What I need is to determine the disjoint components.
    $endgroup$
    – gciriani
    Dec 3 '18 at 13:38










  • $begingroup$
    If your original matrix is symmetric, then p=dmperm(A), B=A(p,p) will put the matrix into block upper triangular form, but since the matrix is symmetric, that will also be block diagonal form. Try it.
    $endgroup$
    – Brian Borchers
    Dec 3 '18 at 15:02










  • $begingroup$
    one of the elements of p turns out to be 0, and dmperm gives an error; my example [0 0 5 1 0; 0 0 0 0 3; 7 0 0 0 0; 2 0 0 0 0; 0 1 0 0 0]
    $endgroup$
    – gciriani
    Dec 3 '18 at 16:42












  • $begingroup$
    Your example matrix isn't symmetric.
    $endgroup$
    – Brian Borchers
    Dec 3 '18 at 16:47










  • $begingroup$
    Even with a symmetric matrix [0 0 1 1 0; 0 0 0 0 1; 1 0 0 0 0; 1 0 0 0 0; 0 1 0 0 0], dmperm gives [3, 5, 1, 0, 2] as a result.
    $endgroup$
    – gciriani
    Dec 4 '18 at 14:56














1












1








1





$begingroup$

The Dulmage-Mendelsohn decomposition (dmperm in MATLAB) can be used to do this for symmetric matrices (or just turn your non-symmetric matrix into a matrix of 0's and 1's with 1's replacing all non-zero entries in the original matrix.)






share|cite|improve this answer









$endgroup$



The Dulmage-Mendelsohn decomposition (dmperm in MATLAB) can be used to do this for symmetric matrices (or just turn your non-symmetric matrix into a matrix of 0's and 1's with 1's replacing all non-zero entries in the original matrix.)







share|cite|improve this answer












share|cite|improve this answer



share|cite|improve this answer










answered Dec 3 '18 at 3:58









Brian BorchersBrian Borchers

6,11111219




6,11111219












  • $begingroup$
    I tried dmperm, but it doesn't seem to perform what I'm trying to determine. According to Octave's help, dmperm is used for block triangular form, which is not what I'm trying to accomplish. What I need is to determine the disjoint components.
    $endgroup$
    – gciriani
    Dec 3 '18 at 13:38










  • $begingroup$
    If your original matrix is symmetric, then p=dmperm(A), B=A(p,p) will put the matrix into block upper triangular form, but since the matrix is symmetric, that will also be block diagonal form. Try it.
    $endgroup$
    – Brian Borchers
    Dec 3 '18 at 15:02










  • $begingroup$
    one of the elements of p turns out to be 0, and dmperm gives an error; my example [0 0 5 1 0; 0 0 0 0 3; 7 0 0 0 0; 2 0 0 0 0; 0 1 0 0 0]
    $endgroup$
    – gciriani
    Dec 3 '18 at 16:42












  • $begingroup$
    Your example matrix isn't symmetric.
    $endgroup$
    – Brian Borchers
    Dec 3 '18 at 16:47










  • $begingroup$
    Even with a symmetric matrix [0 0 1 1 0; 0 0 0 0 1; 1 0 0 0 0; 1 0 0 0 0; 0 1 0 0 0], dmperm gives [3, 5, 1, 0, 2] as a result.
    $endgroup$
    – gciriani
    Dec 4 '18 at 14:56


















  • $begingroup$
    I tried dmperm, but it doesn't seem to perform what I'm trying to determine. According to Octave's help, dmperm is used for block triangular form, which is not what I'm trying to accomplish. What I need is to determine the disjoint components.
    $endgroup$
    – gciriani
    Dec 3 '18 at 13:38










  • $begingroup$
    If your original matrix is symmetric, then p=dmperm(A), B=A(p,p) will put the matrix into block upper triangular form, but since the matrix is symmetric, that will also be block diagonal form. Try it.
    $endgroup$
    – Brian Borchers
    Dec 3 '18 at 15:02










  • $begingroup$
    one of the elements of p turns out to be 0, and dmperm gives an error; my example [0 0 5 1 0; 0 0 0 0 3; 7 0 0 0 0; 2 0 0 0 0; 0 1 0 0 0]
    $endgroup$
    – gciriani
    Dec 3 '18 at 16:42












  • $begingroup$
    Your example matrix isn't symmetric.
    $endgroup$
    – Brian Borchers
    Dec 3 '18 at 16:47










  • $begingroup$
    Even with a symmetric matrix [0 0 1 1 0; 0 0 0 0 1; 1 0 0 0 0; 1 0 0 0 0; 0 1 0 0 0], dmperm gives [3, 5, 1, 0, 2] as a result.
    $endgroup$
    – gciriani
    Dec 4 '18 at 14:56
















$begingroup$
I tried dmperm, but it doesn't seem to perform what I'm trying to determine. According to Octave's help, dmperm is used for block triangular form, which is not what I'm trying to accomplish. What I need is to determine the disjoint components.
$endgroup$
– gciriani
Dec 3 '18 at 13:38




$begingroup$
I tried dmperm, but it doesn't seem to perform what I'm trying to determine. According to Octave's help, dmperm is used for block triangular form, which is not what I'm trying to accomplish. What I need is to determine the disjoint components.
$endgroup$
– gciriani
Dec 3 '18 at 13:38












$begingroup$
If your original matrix is symmetric, then p=dmperm(A), B=A(p,p) will put the matrix into block upper triangular form, but since the matrix is symmetric, that will also be block diagonal form. Try it.
$endgroup$
– Brian Borchers
Dec 3 '18 at 15:02




$begingroup$
If your original matrix is symmetric, then p=dmperm(A), B=A(p,p) will put the matrix into block upper triangular form, but since the matrix is symmetric, that will also be block diagonal form. Try it.
$endgroup$
– Brian Borchers
Dec 3 '18 at 15:02












$begingroup$
one of the elements of p turns out to be 0, and dmperm gives an error; my example [0 0 5 1 0; 0 0 0 0 3; 7 0 0 0 0; 2 0 0 0 0; 0 1 0 0 0]
$endgroup$
– gciriani
Dec 3 '18 at 16:42






$begingroup$
one of the elements of p turns out to be 0, and dmperm gives an error; my example [0 0 5 1 0; 0 0 0 0 3; 7 0 0 0 0; 2 0 0 0 0; 0 1 0 0 0]
$endgroup$
– gciriani
Dec 3 '18 at 16:42














$begingroup$
Your example matrix isn't symmetric.
$endgroup$
– Brian Borchers
Dec 3 '18 at 16:47




$begingroup$
Your example matrix isn't symmetric.
$endgroup$
– Brian Borchers
Dec 3 '18 at 16:47












$begingroup$
Even with a symmetric matrix [0 0 1 1 0; 0 0 0 0 1; 1 0 0 0 0; 1 0 0 0 0; 0 1 0 0 0], dmperm gives [3, 5, 1, 0, 2] as a result.
$endgroup$
– gciriani
Dec 4 '18 at 14:56




$begingroup$
Even with a symmetric matrix [0 0 1 1 0; 0 0 0 0 1; 1 0 0 0 0; 1 0 0 0 0; 0 1 0 0 0], dmperm gives [3, 5, 1, 0, 2] as a result.
$endgroup$
– gciriani
Dec 4 '18 at 14:56


















draft saved

draft discarded




















































Thanks for contributing an answer to Mathematics Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


Use MathJax to format equations. MathJax reference.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3023268%2fdetermine-if-matrix-can-be-permutated-into-block-diagonal-matrix%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

mysqli_query(): Empty query in /home/lucindabrummitt/public_html/blog/wp-includes/wp-db.php on line 1924

How to change which sound is reproduced for terminal bell?

Can I use Tabulator js library in my java Spring + Thymeleaf project?