Nov-23-2017, 03:04 AM
Hello,
I am struggling with great frustration on constructing a matrix.
Here is the whole story: as part of my studies I need to solve some differential partial equations using python. The whole theory is no problem and setting up loops and everything is rather easy. However, I am having a real hard time building this matrix: here is an example of a 3²x3² matrix
4 -1 0 1 0 0 0 0 0
-1 4 -1 0 1 0 0 0 0
0 -1 4 0 0 1 0 0 0
1 0 0 4 -1 0 1 0 0
0 1 0 -1 4 -1 0 1 0
0 0 1 0 -1 4 0 0 1
0 0 0 1 0 0 4 -1 0
0 0 0 0 1 0 -1 4 -1
0 0 0 0 0 1 0 -1 4
So we have a matrix made of blocks:
A1= 4 -1 0
-1 4 -1
0 -1 4
A2 would be the identity and A3 a block of zeros.
(one thing that makes it harder is that the diagonals of -1 are interrupted by zeros).
Finally the biggest problem is that the dimension of each block is N by N (not just 3 by 3) and thus the dimension of the whole matrix will be N² by N².
Maybe I'm being stupid but I can't get my head around it.
Some help would definitely be appreciated...!
I have two main questions:
1:I think it is possible to do that by making an array of arrays, but then, how to initiate the array? and how to implement each array inside?
2: Could a double loop work? Maybe modulo some rectifications afterwards to put the zeros instead?
I would really to make the first option work (it would help me understand more of python); the second option would just be... normal i guess.
Anyways,
Thanks guys!
Max
I am struggling with great frustration on constructing a matrix.
Here is the whole story: as part of my studies I need to solve some differential partial equations using python. The whole theory is no problem and setting up loops and everything is rather easy. However, I am having a real hard time building this matrix: here is an example of a 3²x3² matrix
4 -1 0 1 0 0 0 0 0
-1 4 -1 0 1 0 0 0 0
0 -1 4 0 0 1 0 0 0
1 0 0 4 -1 0 1 0 0
0 1 0 -1 4 -1 0 1 0
0 0 1 0 -1 4 0 0 1
0 0 0 1 0 0 4 -1 0
0 0 0 0 1 0 -1 4 -1
0 0 0 0 0 1 0 -1 4
So we have a matrix made of blocks:
A1= 4 -1 0
-1 4 -1
0 -1 4
A2 would be the identity and A3 a block of zeros.
(one thing that makes it harder is that the diagonals of -1 are interrupted by zeros).
Finally the biggest problem is that the dimension of each block is N by N (not just 3 by 3) and thus the dimension of the whole matrix will be N² by N².
Maybe I'm being stupid but I can't get my head around it.
Some help would definitely be appreciated...!
I have two main questions:
1:I think it is possible to do that by making an array of arrays, but then, how to initiate the array? and how to implement each array inside?
2: Could a double loop work? Maybe modulo some rectifications afterwards to put the zeros instead?
I would really to make the first option work (it would help me understand more of python); the second option would just be... normal i guess.
Anyways,
Thanks guys!
Max