Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Block diagonal matrix from columns

Suppose I have an m x n matrix A .
Is there a way to create B, a (n x m) x n matrix whose "diagonal" is formed by A's columns ?

Example:

A = [1 2;
     3 4]  

B = [1 0;
     3 0;
     0 2;
     0 4]
like image 484
Rui Silva Avatar asked Feb 19 '16 22:02

Rui Silva


People also ask

Why is it a block diagonal matrix?

A block diagonal matrix is therefore a block matrix in which the blocks off the diagonal are the zero matrices, and the diagonal matrices are square.

How do you reduce the diagonal form of a matrix?

To reduce the matrix 'A' in a diagonal form, we have to find the model matrix 'P' and inverse of 'P,' multiplication of P-1AP will give you the diagonal matrix as shown in the image below. The next step would be to find out the characteristic polynomial of A.

Do block diagonal matrices commute?

No, every symmetric matrix and the diagonal matrix doesnot commute. Hence the matrices will not commute.


1 Answers

Here is a way:

  1. Convert A to a cell array of its columns, using mat2cell;
  2. From that cell array generate a comma-separated list, and use it as an input to blkdiag.

Code:

A = [1 2; 3 4];                                   %// example data
C = mat2cell(A, size(A,1), ones(1,size(A,2)));    %// step 1
B = blkdiag(C{:});                                %// step 2

This produces

B =
     1     0
     3     0
     0     2
     0     4
like image 64
Luis Mendo Avatar answered Oct 09 '22 11:10

Luis Mendo