2

I want to enter several matrices at different positions in blocks. There is already a very similar answer here: https://mathematica.stackexchange.com/a/3562/6138

I thought that simply generalizing this function, would yield the correct result. But something seems not to work.

This is my function:

fmetmat[A_?MatrixQ, C_?MatrixQ, D_?MatrixQ, pos_] := 
 SparseArray`SparseBlockMatrix[{{1, 1} -> A, {1 + pos, 1} -> 
 Transpose[C], {1, 1 + pos} -> C, {1 + pos, 1 + pos} -> D}, 
  Dimensions[A] + pos*Dimensions[D]];

But what I get for any integer value of pos is always:

enter image description here

I would like to be able to fill the Matrix in this way, so that if I leave holes in between they show up in the end.

I would like to have, for:

enter image description here

Mathematica graphics

Dmat = IdentityMatrix[5]

And pos=7, the following output

Mathematica graphics

Does somebody understand the logic here and can help me with this?

Thanks!

Santiago
  • 1,201
  • 8
  • 16
  • You have described twice what you don't want, but you have not described what matrix structure you do want. – bill s Nov 19 '14 at 04:21
  • Thanks @bills I uploaded now the desired input and desired output and removed my useless function. – Santiago Nov 21 '14 at 02:09

1 Answers1

3

Perhaps this is a way:

am = IdentityMatrix[3];
cm = {{c, c, c, c, c}, {d, d, d, d, d}, {e, e, e, e, e}};
dm = IdentityMatrix[5]

ArrayFlatten[
  Normal[SparseArray[{{1, 1} -> w[am], {1, 6} -> w[cm], {6, 1} -> 
       w[Transpose@cm], {6, 6} -> w[dm]}, {6, 6}]] /. 
   w -> Sequence] // MatrixForm

where w is just a wrapper to allow SparseArray to parse.

enter image description here

ubpdqn
  • 60,617
  • 3
  • 59
  • 148
  • Sorry, I forgot to accept this. It works really well, This little trick of the wrapper w is pretty nice! – Santiago Nov 24 '14 at 15:07