I have a 4x4 matrix
v1 v2 v3 v4
myM={{a1,a2,c1,c2}, v1
{a2,a3,c2,c3}, v2
{c1,c2,d1,d2}, v3
{c2,c3,d2,d3}} v4
And I want to insert this matrix into a 8x8 matrix as follows:
u1 u2 v1 v2 u3 u4 v3 v4
myLM={{ 0, 0, 0, 0, 0, 0, 0, 0}, u1
{ 0, 0, 0, 0, 0, 0, 0, 0}, u2
{ 0, 0, a1, a2, 0, 0, c1, c2}, v1
{ 0, 0, a2, a3, 0, 0, c2, c3}, v2
{ 0, 0, 0, 0, 0, 0, 0, 0}, u3
{ 0, 0, 0, 0, 0, 0, 0, 0}, u4
{ 0, 0, c1, c2, 0, 0, d1, d2}, v3
{ 0, 0, c2, c3, 0, 0, d2, d3}} v4
Is there a way to do this without index-nightmares?
It would also be great if the answer was general enough, in a sense that it works for 2x2 or also 8x8 matrices that I want to include into a larger matrix.
Both the smaller and the larger matrix have always an even number of columns/rows. And I divide the small and large matrices in 4 blocks and place each sub-block of the small matrix into the corresponding one of the large matrix. So in the given example the index 3 would be given and then it is clear how to insert the matrix (a1-> (3,3) and the rest follows).
So the general idea is I guess, that one has a matrix in some basis representation and wants to have this matrix now in a larger vector space adding the appropriate zeros and matrix elements etc.)
Initial basis:
{v1,v2,...,v1',v2'...}
New Basis (inserting at position n):
{u1,u2,...,un-1,v1,v2,...,un,....,u1',u2',...,un-1',v1',v2',...,un',...}
myM
has many repeated identical elements. Is that always the case, or are they supposed to be all different? I mean, is there a pattern we can assume for the repetitions? Also, do you only need zeros in the large matrix to start with? This would affect the degree to which one could simplify things. $\endgroup$ – Jens Apr 1 '15 at 16:23