# How to produce an "elongated diagonal matrix"?

• Oct 20th 2010, 05:50 AM
Barquentine
How to produce an "elongated diagonal matrix"?
I know this question sounds a bit weird but it basically comes down to this. I want to create a matrix of this type:

$\displaystyle \begin{pmatrix} 1 & 0 & 0\\ 1 & 0 & 0\\ 1 & 0 & 0\\ 0 & 1 & 0\\ 0 & 1 & 0\\ 0 & 1 & 0\\ 0 & 0 & 1\\ 0 & 0 & 1\\ 0 & 0 & 1 \end{pmatrix}$

How do I produce such a matrix, using only matrix multiplication? I've tried a lot of things myself but my understanding of matrix algebra is too limited to "see" how it can be done. Ideally, I would like a general formula where I can specify the amount of columns and the amount of repetitions (1's) in each column. For instance, 2 repeats and 4 columns:

$\displaystyle \begin{pmatrix} 1 & 0 & 0 & 0\\ 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 1 & 0\\ 0 & 0 & 1 & 0\\ 0 & 0 & 0 & 1\\ 0 & 0 & 0 & 1 \end{pmatrix}$

Anyone has suggestions?
• Oct 20th 2010, 04:16 PM
emakarov
What are the factors that you want to use? An obvious solution is to multiply the "elongated diagonal matrix" by the identity matrix...
• Oct 20th 2010, 06:29 PM
Wilmer
Well if you know Basic, easy enough:

u = repeats, v = columns, w = rows

100 GET u, v
110 w = u * v
120 DIM a(w,v) 'set up array/matrix
130 FOR c = 1 TO v
140 FOR r = c * u - u + 1 TO c * u
150 a(r,c) = 1
160 NEXT r
170 NEXT c
180 FOR r = 1 TO w
190 FOR c = 1 TO v
200 PRINT a(r,c)
210 NEXT c
220 NEXT r
If repeats = 5 and colums = 3, this will print:
1 0 0
1 0 0
1 0 0
1 0 0
1 0 0
0 1 0
0 1 0
0 1 0
0 1 0
0 1 0
0 0 1
0 0 1
0 0 1
0 0 1
0 0 1
• Oct 24th 2010, 05:56 AM
Barquentine
Thanks people!