1
$\begingroup$

I am trying to write determinates of Matrices in Mathimatica. I am having an issue since I don't know how to change the brackets of an inserted matrix from the standard "()" to "||". Furthermore (but less crucial), if it is possible to change them from "()" to "[]" that would also be helpful. Last thing how would I create an augmented matrix in Mathematica?

Thank you.

enter image description here enter image description here

$\endgroup$
5
$\begingroup$

Borrowing from another answer here, you can make your matrices display with bars using this function:

makeBrackMat[mat_?MatrixQ] := DisplayForm[RowBox[{
                                StyleBox["|",SpanMaxSize->\[Infinity]],
                                GridBox[mat],
                                StyleBox["|",SpanMaxSize->\[Infinity]]}]];

makeBrackMat[{{1, 3, 2}, {2, 0, 1}, {5, 2, 2}}]

\begin{equation} \begin{array}{|ccccc|} &1 & 3 & 2& \\ &2 & 0 & 1& \\ &5 & 2 & 2& \\ \end{array} \end{equation}

To create an augmented matrix:

Module[{A, B, ans},
 A = {{1, 3, 2}, {2, 0, 1}, {5, 2, 2}};
 B = {{4}, {3}, {1}};
 ans = MapThread[Append, {A, B}];
 Flatten /@ ans // MatrixForm]

\begin{equation} \left( \begin{array}{cccc} 1 & 3 & 2 & 4 \\ 2 & 0 & 1 & 3 \\ 5 & 2 & 2 & 1 \\ \end{array} \right) \end{equation}

$\endgroup$
1
$\begingroup$

To display your matrix with bars, you could use:

Grid[{{1, 3, 2}, {2, 0, 1}, {5, 2, 2}}, Dividers -> {True, False}]

This would give you:

Matrix with bars

$\endgroup$
0
$\begingroup$

Augmented matrix, from What is the most efficient way to add rows and columns to a matrix?:

m = Partition[Range[5^2], 5];
v = Partition[Range@5, 1];

ArrayFlatten[{{m, v}}] // MatrixForm

Mathematica graphics

Output formatting of Det: In TraditionalForm, Det is typeset as vertical bars (actually as "bracketing bars"). We can add a special rule to MakeBoxes to remove the parentheses from around the matrix that also are displayed in TraditionalForm.

MakeBoxes[HoldForm@Det[m_?MatrixQ], TraditionalForm] := 
  MakeBoxes[Interpretation[Det[Grid@m], HoldForm[Det[m]]], TraditionalForm];

HoldForm@Det[{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}] // TraditionalForm

Mathematica graphics

Note that Det must be held; otherwise, the determinant would be computed.

For comparison, this is the default formatting:

Mathematica graphics

$\endgroup$
  • 1
    $\begingroup$ My use case is primarily to do with manually entered text. If there is a way to do that it would be extremely helpful. $\endgroup$ – Alaks McGregor Apr 24 '18 at 22:02
  • $\begingroup$ @AlaksMcGregor How does the Writing Assistant, mentioned in my comment of above suit you? Do you want to be able to evaluate the input or just read it? $\endgroup$ – Michael E2 Apr 24 '18 at 22:27

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.