LaTeX forum ⇒ 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: 6
Joined: Fri Oct 25, 2019 7:12 pm

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

Postby vinc » Fri Oct 25, 2019 7:30 pm

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

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

Postby Stefan Kottwitz » Thu Oct 31, 2019 5:48 am

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
Site admin

vinc
Posts: 6
Joined: Fri Oct 25, 2019 7:12 pm

Postby vinc » Thu Oct 31, 2019 9:23 pm

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 356 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: 9496
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Fri Nov 01, 2019 4:02 am

Here is a way with TikZ:

Code: [Select all] [Expand/Collapse] [Download] ({untitled.tex})
  1. \documentclass{article}
  2. \usepackage{tikz}
  3. \usetikzlibrary{matrix,calc}
  4. \begin{document}
  5. $\det(B) = $
  6. \begin{tikzpicture}[baseline = (m-2-2.base) ]
  7. \matrix (m) [matrix of math nodes,
  8. row sep = .5em, column sep = .5em,
  9. every node/.style = {anchor = base east}] {
  10. \ 1 & 1 & 0 & \ 1 & 1 \\
  11. -1 & 2 & -1 & -1 & 2 \\
  12. -1 &-1 & 3 & -1 & -1 \\
  13. };
  14. \draw
  15. (m-1-1.north west) -- ++(0em,-5em)
  16. (m-1-4.north west) -- ++(0em,-5em)
  17. (m-1-5.north east) -- ++(0em,-5em)
  18. ;
  19. \draw [color = red]
  20. (m-1-1.south east) -- (m-3-3.north west)
  21. (m-1-2.south east) -- (m-3-4.north west)
  22. (m-1-3.south east) -- (m-3-5.north west)
  23. ;
  24. \draw [color = blue]
  25. (m-1-3.south west) -- (m-3-1.north east)
  26. (m-1-4.south west) -- (m-3-2.north east)
  27. (m-1-5.south west) -- (m-3-3.north east)
  28. ;
  29. \end{tikzpicture}
  30. \end{document}


matrix.png
matrix.png (11.97 KiB) Viewed 358 times


Stefan
Site admin

vinc
Posts: 6
Joined: Fri Oct 25, 2019 7:12 pm

Postby vinc » Sat Nov 02, 2019 5:49 am

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: 9496
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Sat Nov 02, 2019 9:10 am

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
Site admin

vinc
Posts: 6
Joined: Fri Oct 25, 2019 7:12 pm

Postby vinc » Sat Nov 02, 2019 7:19 pm

good evening

There is one more problem.

Here is the code below.

Code: [Select all] [Expand/Collapse] [Download] ({untitled.tex})
  1. $det(B)= $
  2.  
  3. \begin{tikzpicture}[baseline = (m-2-2.base) ]
  4. \matrix (m) [matrix of math nodes,
  5. row sep = .5em, column sep = .5em,
  6. every node/.style = {anchor = base east}] {
  7. 1&1&0&1&1 \\
  8. -1&2&-1&-1&2 \\
  9. -1&-1&3&-1&-1 \\
  10.  
  11. };
  12.  
  13. (m-1-1.north west) -- ++(0em,-5em)
  14. (m-1-4.north west) -- ++(0em,-5em)
  15. ; (m-1-5.north east) -- ++(0em,-5em)
  16.  
  17. draw [color = red]
  18. (m-1-1.south east) -- (m-3-3.north west)
  19. (m-1-2.south east) -- (m-3-4.north west)
  20. (m-1-3.south east) -- (m-3-5.north west)
  21. ;
  22. \draw [color = blue]
  23. (m-1-3.south west) -- (m-3-1.north east)
  24. (m-1-4.south west) -- (m-3-2.north east)
  25. (m-1-5.south west) -- (m-3-3.north east)
  26. ;
  27. \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: 9496
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Sun Nov 03, 2019 6:21 am

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

Stefan
Site admin

vinc
Posts: 6
Joined: Fri Oct 25, 2019 7:12 pm

Postby vinc » Sun Nov 03, 2019 6:40 pm

good evening

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

Code: [Select all] [Expand/Collapse] [Download] ({untitled.tex})
  1. $det(B)=$
  2. \begin{tikzpicture}[baseline = (m-2-2.base)]
  3. \matrix (m) [matrix of math nodes,
  4. row sep = .5em, column sep = .5em,
  5. every node/.style = {anchor = base east}] {
  6. \ 1 & 1 & 0 & \ 1 & 1 \\
  7. -1 & 2 &-1 &- 1 & 2 \\
  8. -1 &-1 & 3 & 1 &-1 \\};
  9. (m-1-1.north west) -- ++(0em,-5em)
  10. (m-1-4.north west) -- ++(0em,-5em)
  11. (m-1-5.north east) -- ++(0em,-5em);
  12. \draw [color = red]
  13. (m-1-1.south east) -- (m-3-3.north west)
  14. (m-1-2.south east) -- (m-3-4.north west)
  15. (m-1-3.south east) -- (m-3-5.north west);
  16. \draw [color = blue]
  17. (m-1-3.south west) -- (m-3-1.north east)
  18. (m-1-4.south west) -- (m-3-2.north east)
  19. (m-1-5.south west) -- (m-3-3.north east);
  20. \end{tikzpicture}


Here is the screen print.

latexdet.png
latexdet.png (4.61 KiB) Viewed 278 times


Thank you !

See you soon

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

Postby Stefan Kottwitz » Sun Nov 03, 2019 6:50 pm

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

Stefan
Site admin


Return to “Math & Science”

Who is online

Users browsing this forum: No registered users and 6 guests