Math & ScienceDisplay the determinant of a matrix with the rule of Sarrus.

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
vinc
Posts: 9
Joined: Fri Oct 25, 2019 7:12 pm

Display the determinant of a matrix with the rule of Sarrus.

Post by vinc »

Good evening

I would like to realize a LaTex page with the calculation of the determinant of a matrix with the rule of Sarrus.

I found this tutorial.

https://tex.stackovernet.com/fr/q/103579

It does not work, I get lots of mistakes.

On my computer I have MikeTex.

See you soon

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
Stefan Kottwitz
Site Admin
Posts: 10319
Joined: Mon Mar 10, 2008 9:44 pm

Display the determinant of a matrix with the rule of Sarrus.

Post by Stefan Kottwitz »

Hi vinc,

welcome to the forum!
vinc wrote:It does not work
Which code exactly did you try?
vinc wrote:I get lots of mistakes.
What mistakes? Can you tell us error messages?

Stefan
LaTeX.org admin
vinc
Posts: 9
Joined: Fri Oct 25, 2019 7:12 pm

Display the determinant of a matrix with the rule of Sarrus.

Post by vinc »

Good evening



here is the code

\usepackage[frenchb]{babel}
\usepackage{array, mathtools}
\usepackage{amsmath,amsfonts,amssymb}

\documentclass[11pt,a4paper]{scrbook}

$det(B)=
\begin{array}{|ccc|cc|}
1 & 1 & 0 & 1 & 1\\
-1 & 2 & -1 & -1 & 2\\
-1 &-1 & 3 & -1 & -1\\
\end{array}$


\end{document}


here is the image prints screen.
matrix-example.png
matrix-example.png (2 KiB) Viewed 18806 times
I can not select the lines. Method of the rule of sarrus.

A simple selection line would suffice.

Thanks for your help.

See you soon
User avatar
Stefan Kottwitz
Site Admin
Posts: 10319
Joined: Mon Mar 10, 2008 9:44 pm

Display the determinant of a matrix with the rule of Sarrus.

Post by Stefan Kottwitz »

Here is a way with TikZ:

Code: Select all

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,calc}
\begin{document}
$\det(B) = $
\begin{tikzpicture}[baseline = (m-2-2.base) ]
  \matrix (m) [matrix of math nodes,
               row sep = .5em, column sep = .5em,
               every node/.style = {anchor = base east}] {
    \ 1 & 1 & 0  & \ 1 & 1  \\
     -1 & 2 & -1 &  -1 & 2  \\
     -1 &-1 & 3  &  -1 & -1 \\
  };
  \draw
    (m-1-1.north west) -- ++(0em,-5em)
    (m-1-4.north west) -- ++(0em,-5em)
    (m-1-5.north east) -- ++(0em,-5em)
  ;
  \draw [color = red]
    (m-1-1.south east) -- (m-3-3.north west)
    (m-1-2.south east) -- (m-3-4.north west)
    (m-1-3.south east) -- (m-3-5.north west)
  ;
  \draw [color = blue]
    (m-1-3.south west) -- (m-3-1.north east)
    (m-1-4.south west) -- (m-3-2.north east)
    (m-1-5.south west) -- (m-3-3.north east)
  ;
\end{tikzpicture}
\end{document}
matrix.png
matrix.png (11.97 KiB) Viewed 18808 times
Stefan
LaTeX.org admin
vinc
Posts: 9
Joined: Fri Oct 25, 2019 7:12 pm

Display the determinant of a matrix with the rule of Sarrus.

Post by vinc »

Hello

It did not work, it looks like it is missing a package.

Here is a screenshot of the error.
Image


Here is the code.

\documentclass[11pt,a4paper]{scrbook}
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{textcomp}
\usepackage[a4paper,pdftex,dvips]{geometry}
\usepackage[frenchb]{babel}
\usepackage{array, mathtools}
\usepackage{amsmath,amsfonts,amssymb}
\usepackage{tikz}
\usetikzlibrary{calc,matrix}
\usepackage[font={small,it}]{floatrow}
\usepackage{setspace}
\usepackage{systeme}
\usetikzlibrary{matrix,calc}

\begin{document}

$det(B)= $
\begin{tikzpicture}[baseline = (m-2-2.base) ]
matrix (m) [matrix of math nodes,

row sep = .5em, column sep = .5em,

every node/.style = {anchor = base east}] {

1&1&0&1&1 \\

-1&2&-1&-1&2 \\

-1&-1&3&-1&-1 \\

};

(m-1-1.north west) -- ++(0em,-5em)

(m-1-4.north west) -- ++(0em,-5em)

(m-1-5.north east) -- ++(0em,-5em);

draw [color = red]

(m-1-1.south east) -- (m-3-3.north west)

(m-1-2.south east) -- (m-3-4.north west)

(m-1-3.south east) -- (m-3-5.north west);

\draw [color = blue]

(m-1-3.south west) -- (m-3-1.north east)

(m-1-4.south west) -- (m-3-2.north east)

(m-1-5.south west) -- (m-3-3.north east);

\end{tikzpicture}


\end{document}


I took out \ he rejected them

See you soon
User avatar
Stefan Kottwitz
Site Admin
Posts: 10319
Joined: Mon Mar 10, 2008 9:44 pm

Display the determinant of a matrix with the rule of Sarrus.

Post by Stefan Kottwitz »

You forgot the backslash for the matrix command. Write \matrix instead of just matrix.

And remove the unnecessary empty lines in the code. Empty lines are paragraph breaks, and there should not be a paragraph break within a list of options or in the middle of a matrix.

Btw. it's nice that you provide screenshots, but can you please post them directly here? You can post images as attachments, the "Attachments" link is below the text edit field, when editing a post. See your original post above, I did it there for you, so you can see the image inline. And also btw. the "LaTeX" button is more for inline LaTeX commands, for longer code there is the "Code" button, for the editor. It looks nicer, as in my post above. Just to let you know.

Thanks!

Stefan
LaTeX.org admin
vinc
Posts: 9
Joined: Fri Oct 25, 2019 7:12 pm

Display the determinant of a matrix with the rule of Sarrus.

Post by vinc »

good evening

There is one more problem.

Here is the code below.

Code: Select all

$det(B)= $

\begin{tikzpicture}[baseline = (m-2-2.base) ]
\matrix (m) [matrix of math nodes,
              row sep = .5em, column sep = .5em,
               every node/.style = {anchor = base east}] {
     1&1&0&1&1  \\
     -1&2&-1&-1&2  \\
     -1&-1&3&-1&-1 \\

 };

  (m-1-1.north west) -- ++(0em,-5em)
   (m-1-4.north west) -- ++(0em,-5em)
 ;  (m-1-5.north east) -- ++(0em,-5em)
   
draw [color = red]
    (m-1-1.south east) -- (m-3-3.north west)
    (m-1-2.south east) -- (m-3-4.north west)
   (m-1-3.south east) -- (m-3-5.north west)
   ;
  \draw [color = blue]
    (m-1-3.south west) -- (m-3-1.north east)
    (m-1-4.south west) -- (m-3-2.north east)
   (m-1-5.south west) -- (m-3-3.north east)
;
\end{tikzpicture}
Error on lines 49 (end{tikzpicture}).

! Missing } inserted.<inserted text>}
! Misplaced \cr.<inserted text> \cr \end{tikzpicture}

See you soon
User avatar
Stefan Kottwitz
Site Admin
Posts: 10319
Joined: Mon Mar 10, 2008 9:44 pm

Display the determinant of a matrix with the rule of Sarrus.

Post by Stefan Kottwitz »

It is caused by the paragraph break within the matrix, by that empty line.

Stefan
LaTeX.org admin
vinc
Posts: 9
Joined: Fri Oct 25, 2019 7:12 pm

Display the determinant of a matrix with the rule of Sarrus.

Post by vinc »

good evening

I almost arrived there, it misses the lines of the table.

Code: Select all

$det(B)=$
\begin{tikzpicture}[baseline = (m-2-2.base)]
\matrix (m) [matrix of math nodes,
              row sep = .5em, column sep = .5em,
               every node/.style = {anchor = base east}] {
    \ 1 & 1 & 0  & \  1 & 1  \\
     -1 & 2 &-1  &-   1 & 2  \\
     -1 &-1 & 3  &    1 &-1 \\};
  (m-1-1.north west) -- ++(0em,-5em)
   (m-1-4.north west) -- ++(0em,-5em)
   (m-1-5.north east) -- ++(0em,-5em);
\draw [color = red]
    (m-1-1.south east) -- (m-3-3.north west)
    (m-1-2.south east) -- (m-3-4.north west)
   (m-1-3.south east) -- (m-3-5.north west);
  \draw [color = blue]
    (m-1-3.south west) -- (m-3-1.north east)
    (m-1-4.south west) -- (m-3-2.north east)
   (m-1-5.south west) -- (m-3-3.north east);
\end{tikzpicture}
Here is the screen print.
latexdet.png
latexdet.png (4.61 KiB) Viewed 18728 times
Thank you !

See you soon
User avatar
Stefan Kottwitz
Site Admin
Posts: 10319
Joined: Mon Mar 10, 2008 9:44 pm

Display the determinant of a matrix with the rule of Sarrus.

Post by Stefan Kottwitz »

After the matrix, a \draw command is missing. I had it in the code above.

Stefan
LaTeX.org admin
Post Reply