I'm trying to reproduce the following calculation of a determinant in LaTeX:
Any ideas? I thought of using the tabular
environment but unfortunately I'm not able to align the "=" correctly.
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It only takes a minute to sign up.
Sign up to join this communityI'm trying to reproduce the following calculation of a determinant in LaTeX:
Any ideas? I thought of using the tabular
environment but unfortunately I'm not able to align the "=" correctly.
I just have one question: The numbers in the determine itself are all right aligned. You can see it in column 3, row 1 and 2 in the picture I posted. The 2 is just above the -2 and they are both right aligned, no matter if there is a minus or not. Do you have any idea how to realize that? -- user24295
No, I don't, but according to comments by percusse and Manuel you can do that by loading mathtools instead of amsmath and use \begin{vmatrix*}[r] … \end{vmatrix*}
. I haven't checked though by myself. But I do recomment keep the standard alignement provided by \begin{vmatrix} ... \end{vmatrix}
.
UPDATE with align. Thanks to cmhughes's advice I've replaced eqnarray
with align
and &=&
with &=
. ADDED. As commented by egreg eqnarray
should be avoided (see e.g. here and here) due to spacing discrepancies.
The updated code is:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
\det A &=\left.
\begin{array}{c}
\;\;\text{*)} \\
-1\text{)} \\
-2\text{)} \\
-2\text{)}
\end{array}
\right.
\begin{vmatrix}
1 & 3 & 2 & -6 \\
1 & 2 & -2 & -5 \\
2 & 4 & -2 & -9 \\
2 & 4 & -6 & -9 \notag
\end{vmatrix}
=
\begin{vmatrix}
1 & 3 & 2 & -6 \\
0 & -1 & -4 & 1 \\
0 & -2 & -6 & 3 \\
0 & -2 & -10 & 3
\end{vmatrix}
\\ \notag
&& \\
&=\left.
\begin{array}{c}
\;\;\text{*)} \\
-2\text{)} \\
-2\text{)}
\end{array}
\right.
\begin{vmatrix}
1 & 4 & 1 \\
2 & 6 & 3 \\
2 & 10 & 3
\end{vmatrix}
=
\begin{vmatrix}
1 & 4 & 1 \\
0 & -2 & 1 \\
0 & 2 & 1
\end{vmatrix}
=
\begin{vmatrix}
-2 & 1 \\
2 & 1
\end{vmatrix}
=-4\notag
\end{align}
\end{document}
The Output is:
We can use the following code (with eqnarray)
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{eqnarray*}
\det A\; &=&\left.
\begin{array}{c}
\;\;\text{*)} \\
-1\text{)} \\
-2\text{)} \\
-2\text{)}
\end{array}
\right.
\begin{vmatrix}
1 & 3 & 2 & -6 \\
1 & 2 & -2 & -5 \\
2 & 4 & -2 & -9 \\
2 & 4 & -6 & -9
\end{vmatrix}
=
\begin{vmatrix}
1 & 3 & 2 & -6 \\
0 & -1 & -4 & 1 \\
0 & -2 & -6 & 3 \\
0 & -2 & -10 & 3
\end{vmatrix}
\\
&& \\
&=&\left.
\begin{array}{c}
\;\;\text{*)} \\
-2\text{)} \\
-2\text{)}
\end{array}
\right.
\begin{vmatrix}
1 & 4 & 1 \\
2 & 6 & 3 \\
2 & 10 & 3
\end{vmatrix}
=
\begin{vmatrix}
1 & 4 & 1 \\
0 & -2 & 1 \\
0 & 2 & 1
\end{vmatrix}
=
\begin{vmatrix}
-2 & 1 \\
2 & 1
\end{vmatrix}
=-4
\end{eqnarray*}
\end{document}
to type
eqnarray
. Here is one out of many reasons. (vote capped for today)
\begin{vmatrix*}[r] … \end{vmatrix*}
.
You can define an xvmatrix
environment for the "eXtended" matrix, where you specify the coefficients as a first column:
\documentclass{article}
\usepackage{amsmath}
\makeatletter
\newenvironment{xvmatrix}% eXtended vmatrix
{\left.\array{@{}r |@{\,}*\c@MaxMatrixCols c}}
{\endarray\kern-\arraycolsep\right|}
\makeatother
\begin{document}
\begin{align*}
\det A &=
\begin{xvmatrix}
*) & 1 & 3 & 2 & -6 \\
-1) & 1 & 2 & -2 & -5 \\
-2) & 2 & 4 & -2 & -9 \\
-2) & 2 & 4 & -6 & -9
\end{xvmatrix}
=
\begin{vmatrix}
1 & 3 & 2 & -6 \\
0 & -1 & -4 & 1 \\
0 & -2 & -6 & 3 \\
0 & -2 & -10 & 3
\end{vmatrix}
\\
&=
\begin{xvmatrix}
*) & 1 & 4 & 1 \\
-2) & 2 & 6 & 3 \\
-2) & 2 & 10 & 3
\end{xvmatrix}
=
\begin{vmatrix}
1 & 4 & 1 \\
0 & -2 & 1 \\
0 & 2 & 1
\end{vmatrix}
=
\begin{vmatrix}
-2 & 1 \\
2 & 1
\end{vmatrix}
=-4
\end{align*}
\end{document}
You can use the nicematrix
package.
\documentclass{article}
\usepackage{amsmath,nicematrix}
\begin{document}
\begin{align*}
\det A &=
\begin{vNiceMatrix}[first-col]
*) & 1 & 3 & 2 & -6 \\
-1) & 1 & 2 & -2 & -5 \\
-2) & 2 & 4 & -2 & -9 \\
-2) & 2 & 4 & -6 & -9
\end{vNiceMatrix}
=
\begin{vmatrix}
1 & 3 & 2 & -6 \\
0 & -1 & -4 & 1 \\
0 & -2 & -6 & 3 \\
0 & -2 & -10 & 3
\end{vmatrix}
\\
&=
\begin{vNiceMatrix}[first-col]
*) & 1 & 4 & 1 \\
-2) & 2 & 6 & 3 \\
-2) & 2 & 10 & 3
\end{vNiceMatrix}
=
\begin{vmatrix}
1 & 4 & 1 \\
0 & -2 & 1 \\
0 & 2 & 1
\end{vmatrix}
=
\begin{vmatrix}
-2 & 1 \\
2 & 1
\end{vmatrix}
=-4
\end{align*}
\end{document}
)
to the environment so you don't need to write it all the times. Apart from that, I don't find this notation pleasant (*)
, etc. on the left of the matrix), I don't suggest any other, but I think this is not beautiful.
)
to the definition, but maybe leaving it in the cell makes clearer what the number is for. I don't like the notation, either. There's no need to use the Laplace development at any stage, the usual Gaussian elimination suffices.
mathtools
, and then vmatrix[r]
, right?
I do not consider a good habit introducing such a notation, my experience is that it only confuses people. Mathematical formalism is there for a reason. You can try the following:
\documentclass{article}
\pagestyle{empty}
\usepackage{amsmath}
\begin{document}
\begin{align*}
\det A&=
\underbrace{\begin{vmatrix}
1 & 0 & 0 & 0 \\
-1 & 1 & 0 & 0 \\
-2 & 0 & 1 & 0 \\
-2 & 0 & 0 & 1
\end{vmatrix}}_{=1}
\cdot
\begin{vmatrix}
1 & 3 & 2 & -6 \\
1 & 2 & -2 & -5 \\
2 & 4 & -2 & -9 \\
2 & 4 & -6 & -9
\end{vmatrix}
=
\begin{vmatrix}
1 & 3 & 2 & -6 \\
0 & -1 & -4 & 1 \\
0 & -2 & -6 & 3 \\
0 & -2 & -10 & 3
\end{vmatrix}
\\
&=
\underbrace{\begin{vmatrix}
1 & 0 & 0 \\
-2 & 1 & 0 \\
-2 & 0 & 1
\end{vmatrix}}_{=1}
\cdot
\begin{vmatrix}
1 & 4 & 1 \\
2 & 6 & 3 \\
2 & 10 & 3
\end{vmatrix}
=
\begin{vmatrix}
1 & 4 & 1 \\
0 & -2 & 1 \\
0 & 2 & 1
\end{vmatrix}
=
\begin{vmatrix}
-2 & 1 \\
2 & 1
\end{vmatrix}
=-4
\end{align*}
\end{document}
Somehow, it would make more sense if you tried to demonstrate the column manipulation, because then the triangle unit-determinant matrix would come on the right side. But even this is completely clear IMHO.
Here's another style I made. If you aren't doing determinants, replace the "vmatrix" with "bmatrix". I don't know how to post a picture of what it looks like.
\paragraph{Example}
Evaluate the determinant
\begin{align*}
\begin{vmatrix*}[r]
1 & -12 & 5 & -3 \\
2 & -21 & 22 & -7 \\
2 & -9 & 41 & -10 \\
0 & 3 & 7 & 3
\end{vmatrix*}.
\end{align*}
\paragraph{Solution}
\begin{align*}
\begin{vmatrix*}[r]
1 & -12 & 5 & -3 \\
2 & -21 & 22 & -7 \\
2 & -9 & 41 & -10 \\
0 & 3 & 7 & 3
\end{vmatrix*}
&=
\begin{vmatrix*}[r]
1 & -12 & 5 & -3 \\
0 & 3 & 12 & -1 \\
0 & 15 & 31 & -4 \\
0 & 3 & 7 & 3
\end{vmatrix*}
\quad
\begin{matrix*}[l]
\\
\leftarrow -2r_1+r_2 \ \text{\scriptsize (no change in determinant)} \\
\leftarrow -2r_2+r_3 \ \text{\scriptsize (no change in determinant)} \\
\\
\end{matrix*} \\
&=
-\begin{vmatrix*}[r]
1 & -3 & 5 & -12 \\
0 & -1 & 12 & 3 \\
0 & -4 & 31 & 15 \\
0 & 3 & 7 & 3
\end{vmatrix*}
\quad
\begin{matrix*}[l]
\\
\leftarrow c_2 \leftrightarrow c_4 \ \text{\scriptsize (negate determinant)} \\
\\
\\
\end{matrix*} \\
&=
-\begin{vmatrix*}[r]
1 & -3 & 5 & -12 \\
0 & 1 & -12 & -3 \\
0 & 4 & -31 & -15 \\
0 & 3 & 7 & 3
\end{vmatrix*}
\quad
\begin{matrix*}[l]
\\
\leftarrow -r_2 \ \text{\scriptsize (negate determinant)} \\
\leftarrow -r_3 \ \text{\scriptsize (negate determinant)} \\
\\
\end{matrix*} \\
&=
-\begin{vmatrix*}[r]
1 & -3 & 5 & -12 \\
0 & 1 & -12 & -3 \\
0 & 0 & 17 & -3 \\
0 & 0 & 43 & 12
\end{vmatrix*}
\quad
\begin{matrix*}[l]
\\
\\
\leftarrow -4r_2+r_3 \ \text{\scriptsize (no change in determinant)} \\
\leftarrow -3r_2+r_4 \ \text{\scriptsize (no change in determinant)}
\end{matrix*} \\
&=
-17\begin{vmatrix*}[r]
1 & -3 & 5 & -12 \\
0 & 1 & -12 & -3 \\
0 & 0 & 1 & -\nicefrac{3}{17} \\
0 & 0 & 43 & 12
\end{vmatrix*}
\quad
\begin{matrix*}[l]
\\
\\
\leftarrow \nicefrac{1}{17}r_3 \ \text{\scriptsize (factor out 17)} \\
\\
\end{matrix*} \\
&=
-17\begin{vmatrix*}[r]
1 & -3 & 5 & -12 \\
0 & 1 & -12 & -3 \\
0 & 0 & 1 & -\nicefrac{3}{17} \\
0 & 0 & 0 & \nicefrac{333}{17}
\end{vmatrix*}
\quad
\begin{matrix*}[l]
\\
\\
\\
\leftarrow -43r_3+r_4 \ \text{\scriptsize (no change in determinant)}
\end{matrix*} \\
&= -17\left(\frac{333}{17}\right) = \bm{-333}.
\end{align*}