3
$\begingroup$

I have four square matrices 5x5 and I need to join them into one 10x10. I tried various commands like Join, Append, Union and none work properly. Any advice?

$\endgroup$

closed as off-topic by Henrik Schumacher, anderstood, MarcoB, eyorble, bbgodfrey May 12 '18 at 18:04

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – Henrik Schumacher, anderstood
If this question can be reworded to fit the rules in the help center, please edit the question.

8
$\begingroup$
(matrices = RandomInteger[{0, 99}, {2, 2, 5, 5}]) // MatrixForm
ArrayFlatten[matrices] // MatrixForm
$\endgroup$
3
$\begingroup$

KroneckerProduct seems to be deemed as something else, however I would say that all roads lead to Rome.

fiveByFive = RandomInteger[100, {4, 5, 5}];
posMat = {{{1, 0}, {0, 0}}, {{0, 1}, {0, 0}}, {{0, 0}, {1, 0}}, {{0, 0}, {0, 1}}};
MapThread[KroneckerProduct, {posMat, fiveByFive}] // Total

Update

posMat can have an alternative definition

posMat = SparseArray[{{1, 1, 1}, {2, 1, 2}, {3, 2, 1}, {4, 2, 2}} -> 1, {4, 2, 2}]
$\endgroup$
  • $\begingroup$ Here is the problem. I am using Mathematica 4 and it doesn't have the commands listed above. What should I do? $\endgroup$ – user1765636 Apr 28 '18 at 20:53
  • 1
    $\begingroup$ @user1765636 For future questions, it would be a good idea to post your Mathematica version directly into the question. Version 4 is almost 18 years old and this constrains the possible solutions considerably. $\endgroup$ – Henrik Schumacher Apr 28 '18 at 22:39
1
$\begingroup$

If you really have to use version 4, you might try Flatten like this:

matrices = RandomReal[{-1, 1}, {4, 5, 5}];
Flatten[Partition[matrices, 2], {{1, 3}, {2, 4}}]

However, I am not sure if this use of Flatten was already established in version 4. Just give it a try.

Another alternative is

Join @@ (Join[Sequence @@ #, 2] & /@ Partition[matrices,2])

Or maybe

Transpose[
 Join @@ Transpose[
   Join @@@ Transpose[Partition[matrices, 2]], {1, 3, 2}]]

will do.

$\endgroup$
  • $\begingroup$ This is not what I need. I have 4 matrices n1, n2, n3, n4. Please write the command for me. $\endgroup$ – user1765636 Apr 30 '18 at 19:56
  • 1
    $\begingroup$ What about some example data? The more effort you put into your question the likelier you get the answer you need. $\endgroup$ – Henrik Schumacher Apr 30 '18 at 19:58
  • $\begingroup$ I have 4 5x5 matrices n1, n2, n3, n4. I need to combine them into one 10x10 matrix with n1 in the top left corner, n2 in the top right, n3 in the bottom left and n4 in the bottom right, and I am using Mathematica 4. I got above example of using join, what should I put in this command instead of parameter 'matrices'? I tried {{n1, n2},{ n3, n4}}. It doesn't work. I also tried Flatten[{{n1,n2},{n3, n4}},2]. It doesn't work. If I change 2x3, then I get one-dimensional list of 100 items. What am I doing wrong? $\endgroup$ – user1765636 Apr 30 '18 at 20:49
  • $\begingroup$ I edited the answer. Try matrices = {n1, n2, n3, n4}. $\endgroup$ – Henrik Schumacher Apr 30 '18 at 20:51
  • $\begingroup$ Mathematica 4 does not understand two join commands, because it repeats one of them in the printout. Any other ideas? $\endgroup$ – user1765636 May 1 '18 at 20:46

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