5
$\begingroup$

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}}]]
$\endgroup$
  • $\begingroup$ Why not ArrayFlatten[{{c1, IdentityMatrix[30]}, {0, c2}}]? $\endgroup$ – J. M. is away Nov 23 '15 at 13:59
  • $\begingroup$ this doesn't work either :( $\endgroup$ – Sertii Nov 23 '15 at 14:03
  • 2
    $\begingroup$ Try ArrayFlatten[{{c1, PadRight[IdentityMatrix[30], {Automatic, 48}]}, {0, c2}}]] then. $\endgroup$ – J. M. is away Nov 23 '15 at 14:09
  • $\begingroup$ Awesome! That worked! $\endgroup$ – Sertii Nov 23 '15 at 14:10
  • $\begingroup$ Yes they are both square. C1 and C2 are companion matrices and i'm trying to make the Jordan rational normal form. I don't think there is a problem, I might be wrong though $\endgroup$ – Sertii Nov 23 '15 at 14:15
2
$\begingroup$
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]
$\endgroup$
  • $\begingroup$ I ended up using an anwer provided above but thank you for taking the time anyway! $\endgroup$ – Sertii Nov 23 '15 at 14:16
  • 1
    $\begingroup$ 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 $\endgroup$ – Jason B. Nov 23 '15 at 14:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.