Ask Your Question
0

Create a band matrix with repeating and alternating values

asked 2017-03-24 20:09:22 +0100

jrojasqu gravatar image

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?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2017-03-25 00:24:44 +0100

ndomes gravatar image
var('a b c d e f g')
A = matrix(2,2,[a,b,b,e])
C = matrix(2,2,[c,d,f,g])
B = block_matrix(2,2, [A,C,C.transpose(),A])
M = matrix(SR,10,10)
for k in range(4):
    M.set_block(2*k,2*k,B)
M
edit flag offensive delete link more
0

answered 2017-03-25 01:45:53 +0100

danny gravatar image

image description

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-03-24 20:09:22 +0100

Seen: 362 times

Last updated: Mar 25 '17