3
$\begingroup$

Consider:

$$A=\left[\begin{array}{rrr|rr} 2 & -3 & 1 & 0 & -4\\ 1 & 5 & -2 & 3 & -1\\ \hline 0 & -4 & -2 & 7 & -1 \end{array}\right]$$

Let's say I am using a Mathematica Notebook and I've used the Writing Assistant to select Math Cells->Equal Symbol Aligned Math Cell. How can I display the partitioned matrix $A$? Has anyone done this before?

$\endgroup$
5
$\begingroup$

Borrowing some of the display-related code for TransformationFunction[], I came up with this:

MakeBoxes[PartitionedMatrixForm[M_, {p_Integer, q_Integer}], fmt_] ^:= Module[{mat},
          mat = If[Unevaluated[M] =!= {{}} && MatrixQ[Unevaluated[M]] && 
                   And @@ MapThread[0 <= Abs[#2] <= #1 - 1 &, {Dimensions[M], {p, q}}],
                   MakeBoxes[Grid[M, Dividers ->
                               {{False, If[q != 0, {q + Sign[q] -> True}, False]},
                                {False, If[p != 0, {p + Sign[p] -> True}, False]}}], fmt], 
                   MakeBoxes[M, fmt]];
          mat = If[MatchQ[mat, TagBox[_GridBox, "Grid", ___]], 
                   RowBox[{"(", TagBox[mat[[1]], #1 &], ")"}], MakeBoxes[M, fmt]]; 
          mat]

which gives partitioned matrix display partitioned matrix display

| improve this answer | |
$\endgroup$

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.