7

Now, I'm aware of the threads existing about this question such as:

How to enter matrices in block matrix format?

How to form a block-diagonal Matrix from a list of matrices?

But I wasn't able to find the solution to my problem there. I need to make a matrix $$ \begin{pmatrix} C_1 &I\\ 0 & C_2 \end{pmatrix} $$

My problem is that $C_1$ and $C_2$ are of different sizes! $C_1$ is of size 30 and $C_2$ is of size 48. So one would expect the following code to work:

MatrixForm[ArrayFlatten[{{c1, IdentityMatrix[30], 0}, {0, c2}}]]

or maybe

MatrixForm[ArrayFlatten[{{c1, IdentityMatrix[30], ConstantArray[0,{18,18}]}, 
{ConstantArray[0,{30,30}], c2}}]]

But neither actually works!

Edit

I ended up using J.M's answer:

ArrayFlatten[{{c1, PadRight[IdentityMatrix[30], {Automatic, 48}]}, {0, c2}}]]
Sertii
  • 135
  • 7

1 Answers1

3
m30 = ConstantArray[3, {30, 30}];
i30 = IdentityMatrix[30];
m48 = ConstantArray[4, {48, 48}];
m12 = ConstantArray[0, {48, 12}];

Transpose@Join[m30, i30]~Join~Join[m12, m48, 2]
eldo
  • 67,911
  • 5
  • 60
  • 168
  • I ended up using an anwer provided above but thank you for taking the time anyway! – Sertii Nov 23 '15 at 14:16
  • 1
    They are different answers, J.M.'s follows the idea that C1 and C2 have no columns in common - which can be inferred from your sketch above. Eldo's answer maintains the fact that I is an identity matrix. You can't have both: if I is an identity matrix, then the shape described doesn't make sense – Jason B. Nov 23 '15 at 14:25