### misc.permute2blockTriangle: new output argument for permutation indices

parent a4537ba8
 function [triangularMatrix, permutationMatrix] = permute2blockTriangle(A) function [triangularMatrix, permutationMatrix, permutationIdx] = permute2blockTriangle(A) % MISC.PERMUTE2BLOCKTRIANGLE permutes the matrix A, if possible, to a lower block triangular matrix. % The implementation is based on using methods for digraphs, see matlab documentation for digraph. % ... ... @@ -8,6 +8,10 @@ function [triangularMatrix, permutationMatrix] = permute2blockTriangle(A) % permutation matrix such that % triangularMatrix = permutationMatrix * A * permutationMatrix.' % % [triangularMatrix, permutationMatrix, permutationIdx] = misc.permute2blockTriangle(A) also % returns the double array permutationIdx, which contains the indexes for the permutation of % columns of A. % % Note that inv(permutationMatrix) = permutationMatrix.' (which holds for all so-called % permutation matrices). ... ... @@ -19,13 +23,13 @@ myDiagraph = digraph(A); % As agentsBlockNumber defines which agent belongs to which group, the following for loop defines % how they will be sorted. sortIdx = zeros(size(A, 1), 1); permutationIdx = zeros(size(A, 1), 1); for blockIdx = numel(blockSize) : -1 : 1 sortIdx(sum(blockSize(numel(blockSize):-1:(blockIdx+1))) + (1:blockSize(blockIdx)), 1) ... permutationIdx(sum(blockSize(numel(blockSize):-1:(blockIdx+1))) + (1:blockSize(blockIdx)), 1) ... = find(agentsBlockNumber - blockIdx == 0); end permutationMatrix = full(sparse(1:1:size(A, 1), sortIdx, 1)); permutationMatrix = full(sparse(1:1:size(A, 1), permutationIdx, 1)); triangularMatrix = permutationMatrix * A * permutationMatrix.'; end % permute2blockTriangle() \ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!