How do I build this block matrix in python?

Viewed 952

I want to build a block matrix for a system of equation with n points. The result is an (2n+2)x(2n+2) matrix. In example, for 2 points the matrix is:

1 0 0 0 0 0
a b c d 0 0
e f g h 0 0
0 0 a b c d
0 0 e f g h
0 0 0 0 0 1

For 3 points the matrix is

1 0 0 0 0 0 0 0
a b c d 0 0 0 0
e f g h 0 0 0 0
0 0 a b c d 0 0
0 0 e f g h 0 0
0 0 0 0 a b c d
0 0 0 0 e f g h
0 0 0 0 0 0 0 1

Here, a, b, c, d, e, f, g, h are float values known ahead of time. But I don't know value of n ahead of time. Is there a library in python to do this? I've looked at scipy.sparse.diag, scipy.linalg.block_diag and numpy.bat, but these do not achieve what I want.

3 Answers
Related