I do know how to do this for matrices on the diagonal, but I can't figure out how to do this for matrices on both the diagonal and the upper diagonal. Can someone help me?
Asked
Active
Viewed 115 times
1
1 Answers
1
Seems like Band can be used:
foo[diag_,upperdiag_] := SparseArray[{
Band[{1,1}]->diag,
Band[{1,Dimensions[diag[[1]]][[2]]+1}]->upperdiag}] // Normal;
Example:
SeedRandom[1];
r[dimx_,dimy_] := RandomInteger[{1,9},{dimx,dimy}];
foo[{r[3,3],r[2,2],r[2,3],r[3,2]},{r[3,2],r[2,3],r[2,2]}] // MatrixForm
user293787
- 11,833
- 10
- 28
-
-
You are welcome. Just a comment: Your question risks being closed as a duplicate of this question. If you are interested in keeping the question open, you should explain in your question (you can still edit!) why you think it is not a duplicate, or agree that it is a duplicate, whatever the case may be. Also, usually one should post code, not screenshots of code. Have a nice day! – user293787 Dec 10 '22 at 13:43


Foldyou could have usedArrayFlatten[{{a,0,0,0},{0,b,0,0},{0,0,c,0},{0,0,0,d}}]. Then replace0's above the diagonal with matrices, if that is what you are asking. – user293787 Dec 09 '22 at 17:28