Thread: How to produce an "elongated diagonal matrix"?

1. 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:

$\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:

$\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?

2. What are the factors that you want to use? An obvious solution is to multiply the "elongated diagonal matrix" by the identity matrix...

3. 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

4. Thanks people!