Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Create a band matrix with repeating and alternating values

I have 7 values: a, b, c, d, e, f and g

I would like to construct an m by n matrix in this way:

[ a b c d 0 0 0 0 . . . .]
[ b e f g 0 0 0 0 . . . .]
[ c f a b c d 0 0 . . . .]
[ d g b e f g 0 0 . . . .]
[ 0 0 c f a b c d 0 0 . .]
[ 0 0 d g b e f g 0 0 . .]
[ . . 0 0 c f a b c d . .]
[ . . 0 0 d g b e f g . .]

And so forth...

Therefore, the desired matrix is symmetrical. Values a and e alternate on the main diagonal; values b and f alternate on the 1st upper diagonal; values c and g alternate on the 2nd upper diagonal; values d and 0 alternate on the 3rd upper diagonal. I would like to be able to specify the matrix size with m by n parameters (even though the resulting matrix is non-square).

What would be an efficient way to construct this matrix?