3

I am currently working on a document in Overleaf, and I am having trouble formatting my equations and mathematical expressions. Specifically, I want to enumerate the steps of the solution with text describing the steps along the way, but I am having trouble aligning equations and getting them to display properly.

I keep getting several error messages such as "Missing $ inserted," "Command \item invalid in math mode," "Something's wrong--perhaps a missing \item," and "Command \end{enumerate} invalid in math mode."

I believe these errors are related to my use of mathematical symbols and expressions in the document. I understand that I need to enclose all mathematical expressions and symbols with special markers to create 'math mode'. I have tried using $...$ for inline math mode, and \[...\] or one of the mathematical environments (e.g. equation) for display math mode, but I still seem to be making some mistakes.

Can someone please help me with aligning my equations and getting them to display properly? Any advice or suggestions would be greatly appreciated. Thank you in advance!

It's partly in Swedish, I had to translate the text to English (for context):

\documentclass{article}
\usepackage{graphicx} % Required for inserting images
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{geometry}
\title{Krysstal 2}
\author{D}
\date{April 2023}

\begin{document}

\section*{Uppgift}
3.  Calculate the determinant of the matrix below. Note that the number of multiplications and additions needed to calculate the determinant depends on how it is expanded!

$$
\left[\begin{array}{lllll}
1 & 0 & 0 & 0 & 4 \\
0 & 7 & 0 & 5 & 0 \\
0 & 2 & 1 & 3 & 0 \\
0 & 6 & 0 & 8 & 0 \\
0 & 0 & 0 & 0 & 1
\end{array}\right] .
$$
\subsection*{Lösning}
To calculate the determinant of a $5 \times 5$ matrix, we use cofactor expansion. First, we choose the row or column with the most zeros, which in this case is the last row, to reduce the problem by one step. Then, we write the determinant as a sum of products of terms. Each term corresponds to an element in the selected row or column and its minor, obtained by deleting the row and column that correspond to the element, multiplied by $(-1)^{i+j}$ where $i$ and $j$ are the row and column indices of the element. Then we expand along the selected row using cofactor expansion, which reduces the problem by one more step. Finally, we use Sarrus's rule to calculate the determinant of a $3 \times 3$ matrix.

\begin{enumerate}
    \item We are to calculate the determinant of a $5 \times 5$ matrix. To solve the problem, we will use cofactor expansion, choosing the row or column with the most zeros. In this case, it is the last row that has the most zeros (4). We have a $5 \times 5$ matrix that looks like this:

$$
\left[\begin{array}{lllll}
1 & 0 & 0 & 0 & 4 \\
0 & 7 & 0 & 5 & 0 \\
0 & 2 & 1 & 3 & 0 \\
0 & 6 & 0 & 8 & 0 \\
0 & 0 & 0 & 0 & 1
\end{array}\right] .
$$

\item Then we write out the determinant by taking a sum of products. We use the last row as our expansion row, since it has the most zeros. We get:

$$
\left|\begin{array}{ccccc}
1 & 0 & 0 & 0 & 4 \\
0 & 7 & 0 & 5 & 0 \\
0 & 2 & 1 & 3 & 0 \\
0 & 6 & 0 & 8 & 0 \\
0 & 0 & 0 & 0 & 1
\end{array}\right| = (0)(-1)^{5+1}\left| \begin{array}{cccc}
0 & 0 & 0 & 4 \\
7 & 0 & 5 & 0 \\
2 & 1 & 3 & 0 \\
6 & 0 & 8 & 0
\end{array}\right| 
+ (0)(-1)^{5+2}\left| \begin{array}{cccc}
1 & 0 & 0 & 4 \\
0 & 0 & 5 & 0 \\
0 & 1 & 3 & 0 \\
0 & 0 & 8 & 0 \\
\end{array}\right| \\
+ (0)(-1)^{5+3}\left| \begin{array}{cccc}
1 & 0 & 0 & 4 \\
0 & 7 & 5 & 0 \\
0 & 2 & 3 & 0 \\
0 & 6 & 8 & 0 
\end{array}\right| \\
$$
$$
+ (0)(-1)^{5+4} \left|\begin{array}{cccc}
1 & 0 & 0 & 0 \\
0 & 7 & 0 & 5 \\
0 & 2 & 1 & 3 \\
0 & 6 & 0 & 8
\end{array}\right|
+ (1)(-1)^{5+5} \left|\begin{array}{cccc}
1 & 0 & 0 & 0 \\
0 & 7 & 0 & 5 \\
0 & 2 & 1 & 3 \\
0 & 6 & 0 & 8
\end{array}\right| \\
= \left|\begin{array}{llll}
1 & 0 & 0 & 0 \\
0 & 7 & 0 & 5 \\
0 & 2 & 1 & 3 \\
0 & 6 & 0 & 8
\end{array}\right| $$\\
\text{Utvecklar längs rad 1:}\\$$
$$
$$
\left|\begin{array}{cccc}
1 & 0 & 0 & 0 \\
0 & 7 & 0 & 5 \\
0 & 2 & 1 & 3 \\
0 & 6 & 0 & 8
\end{array}\right|=(1)(-1)^{1+1}\left|\begin{array}{ccc}
7 & 0 & 5 \\
2 & 1 & 3 \\
6 & 0 & 8
\end{array}\right| + (0)(-1)^{1+2} \left|\begin{array}{ccc}
0 & 0 & 5 \\
0 & 1 & 3 \\
0 & 0 & 8
\end{array}\right|+(0)(-1)^{1+3}\left|\begin{array}{ccc}
0 & 7 & 5 \\
0 & 2 & 3 \\
0 & 6 & 0
\end{array}\right| \\ $$+ (0)(-1)^{1+4} \left|\begin{array}{lll}
     0 & 7 & 0  \\
     0 & 2 & 1 \\
     0 & 6 & 0
\end{array}\right| = \left|\begin{array}{lll}
0 & 7 & 5 \\
0 & 2 & 3 \\
0 & 6 & 8\end{array}\right|
$$
\\
$$
\item \text{Using Sarrus' rule to calculate the determinant:} \\
$$\begin{vmatrix}7&0&5\\ 2&1&3\\ 6&0&8\end{vmatrix} \begin{matrix}7&0\\ 2&1\\ 6&0\end{matrix} =\left( 7\cdot 1\cdot 8\right)  -\left( 6\cdot 1\cdot 5\right)  =26$$
\end{enumerate}

\end{document}

And with \[…\] delimiter (no significant changes that I could notice. Note, it's in Swedish):

\documentclass{article}
\usepackage{graphicx} % Required for inserting images
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{geometry}
\title{Krysstal 2}
\author{D}
\date{April 2023}

\begin{document}

\section*{Uppgift}
3. Beräkna determinanten till matrisen nedan. Notera att antalet multiplikationer och additioner man behöver göra beror på hur man utvecklar determinanten!

\[
\left[\begin{array}{lllll}
1 & 0 & 0 & 0 & 4 \\
0 & 7 & 0 & 5 & 0 \\
0 & 2 & 1 & 3 & 0 \\
0 & 6 & 0 & 8 & 0 \\
0 & 0 & 0 & 0 & 1
\end{array}\right] .
\]
\subsection*{Lösning}
För att beräkna determinanten för en $5 \times 5$ matris används kofaktorutveckling. Först väljs raden eller kolumnen som har flest nollor, i detta fall den sista raden, för att reducera problemet ett steg. Sedan skrivs determinanten som en summa av produkter av termer. Varje term svarar mot ett element i den valda raden eller kolumnen och dess minor, som fås genom att stryka bort raden och kolumnen som korresponderar med elementet, multiplicerat med $(-1)^{i+j}$ där $i$ och $j$ är rad- respektive kolumnindex för elementet. Därefter utvecklar vi längs raden med hjälp av kofaktorutveckling, vilket reducerar problemet ytterligare ett steg. Slutligen används Sarrus regel för att beräkna determinanten av en $3 \times 3$ matris.

\begin{enumerate}
    \item Vi ska beräkna determinanten för en $5 \times 5$ matris. För att lösa problemet kommer vi använda cofaktor expansion, där vi väljer den rad eller kolumn som har flest nollor. I detta fall är det sista raden som har flest nollor (4). Vi har en $5 \times 5$ matris som ser ut som följer:

\[
\left[\begin{array}{lllll}
1 & 0 & 0 & 0 & 4 \\
0 & 7 & 0 & 5 & 0 \\
0 & 2 & 1 & 3 & 0 \\
0 & 6 & 0 & 8 & 0 \\
0 & 0 & 0 & 0 & 1
\end{array}\right] .
\]

\item Sedan skriver vi ut determinanten genom att göra en summa av produkter. Vi använder den sista raden som vår utvecklingsrad, eftersom den har flest nollor. Vi får:

\[
\left|\begin{array}{ccccc}
1 & 0 & 0 & 0 & 4 \\
0 & 7 & 0 & 5 & 0 \\
0 & 2 & 1 & 3 & 0 \\
0 & 6 & 0 & 8 & 0 \\
0 & 0 & 0 & 0 & 1
\end{array}\right| = (0)(-1)^{5+1}\left| \begin{array}{cccc}
0 & 0 & 0 & 4 \\
7 & 0 & 5 & 0 \\
2 & 1 & 3 & 0 \\
6 & 0 & 8 & 0
\end{array}\right| 
+ (0)(-1)^{5+2}\left| \begin{array}{cccc}
1 & 0 & 0 & 4 \\
0 & 0 & 5 & 0 \\
0 & 1 & 3 & 0 \\
0 & 0 & 8 & 0 \\
\end{array}\right| \\
+ (0)(-1)^{5+3}\left| \begin{array}{cccc}
1 & 0 & 0 & 4 \\
0 & 7 & 5 & 0 \\
0 & 2 & 3 & 0 \\
0 & 6 & 8 & 0 
\end{array}\right| \\
\]
\[
+ (0)(-1)^{5+4} \left|\begin{array}{cccc}
1 & 0 & 0 & 0 \\
0 & 7 & 0 & 5 \\
0 & 2 & 1 & 3 \\
0 & 6 & 0 & 8
\end{array}\right|
+ (1)(-1)^{5+5} \left|\begin{array}{cccc}
1 & 0 & 0 & 0 \\
0 & 7 & 0 & 5 \\
0 & 2 & 1 & 3 \\
0 & 6 & 0 & 8
\end{array}\right| \\
= \left|\begin{array}{llll}
1 & 0 & 0 & 0 \\
0 & 7 & 0 & 5 \\
0 & 2 & 1 & 3 \\
0 & 6 & 0 & 8
\end{array}\right| \]\\
\text{Utvecklar längs rad 1:}\\
\[
\left|\begin{array}{cccc}
1 & 0 & 0 & 0 \\
0 & 7 & 0 & 5 \\
0 & 2 & 1 & 3 \\
0 & 6 & 0 & 8
\end{array}\right|=(1)(-1)^{1+1}\left|\begin{array}{ccc}
7 & 0 & 5 \\
2 & 1 & 3 \\
6 & 0 & 8
\end{array}\right| + (0)(-1)^{1+2} \left|\begin{array}{ccc}
0 & 0 & 5 \\
0 & 1 & 3 \\
0 & 0 & 8
\end{array}\right|+(0)(-1)^{1+3}\left|\begin{array}{ccc}
0 & 7 & 5 \\
0 & 2 & 3 \\
0 & 6 & 0
\end{array}\right| \\ \]+ (0)(-1)^{1+4} \left|\begin{array}{lll}
     0 & 7 & 0  \\
     0 & 2 & 1 \\
     0 & 6 & 0
\end{array}\right| = \left|\begin{array}{lll}
0 & 7 & 5 \\
0 & 2 & 3 \\
0 & 6 & 8\end{array}\right|
\[
\\
\]
\item \text{Använder Sarrus regel för att räkna ut determinanten:} \\
\[\begin{vmatrix}7&0&5\\ 2&1&3\\ 6&0&8\end{vmatrix} \begin{matrix}7&0\\ 2&1\\ 6&0\end{matrix} =\left( 7\cdot 1\cdot 8\right)  -\left( 6\cdot 1\cdot 5\right)  =26\]
\end{enumerate}

\end{document}
4
  • 1
    As a note, once TeX encounters an error, it makes a guess as to how to fix it. This guess is often wrong, leading to many more errors. So you should focus on just the first error. Also, you should use \[...\] instead of $$...$$.
    – Teepeemm
    Commented Apr 27, 2023 at 2:20
  • @Teepeemm Thank you for the advice. However, there were actually several other issues with the code that I had to address. After making the suggested changes, I still encountered additional errors such as "Bad math environment delimiter," "Missing \endgroup inserted," "Lonely \item--perhaps a missing list environment," and "Extra \endgroup." I edited in the code with the new delimiter that you suggested. Thanks.
    – cricket900
    Commented Apr 27, 2023 at 2:30
  • But if you look at the line of the first error that Overleaf sees, what are you trying to have TeX do at that point? (I would also suggest reading a bit about the amsmath environments bmatrix, vmatrix, and multline.)
    – Teepeemm
    Commented Apr 27, 2023 at 2:39
  • @Teepeemm Thank you for your suggestion. I've actually already read about those amsmath environments, and I've been trying to use them in my code. However, I'm still encountering errors, and the one you mentioned earlier is not the only issue I'm facing. I appreciate your help though.
    – cricket900
    Commented Apr 27, 2023 at 2:45

1 Answer 1

5

Your code contains a number of errors of commission and omission. The most serious issue, in my opinion, is the failure to use any the multi-row math environments of the amsmath package -- and the align* environment in particular -- to typeset the two three-row expressions for the development of the determinants.

My main suggestion to you would be to perform a line-by-line comparison of your original code with the code shown below. Studying section 3, "Displayed equations", of the user guide of the amsmath package and, in particular, studying the syntax of the align and align* environments in subsection 3.6, "Equation groups with mutual alignment", would probably be an excellent idea. If you have questions about what some of the code shown below does, please let me know.

enter image description here

enter image description here

\documentclass{article}
\usepackage{graphicx} % Required for inserting images
\usepackage{amsmath,amssymb}

\usepackage[a4paper,margin=2.5cm]{geometry} % set page parameters as needed
\usepackage[T1]{fontenc}
\usepackage[swedish]{babel}
\usepackage{enumitem}

\begin{document}

\section*{Uppgift}

3. Beräkna determinanten till matrisen nedan. Notera att antalet multiplikationer och additioner man behöver göra beror på hur man utvecklar determinanten!
\[
\begin{bmatrix}
1 & 0 & 0 & 0 & 4 \\
0 & 7 & 0 & 5 & 0 \\
0 & 2 & 1 & 3 & 0 \\
0 & 6 & 0 & 8 & 0 \\
0 & 0 & 0 & 0 & 1
\end{bmatrix} 
\]

\subsection*{Lösning}
För att beräkna determinanten för en $5 \times 5$ matris används kofaktorutveckling. Först väljs raden eller kolumnen som har flest nollor, i detta fall den sista raden, för att reducera problemet ett steg. Sedan skrivs determinanten som en summa av produkter av termer. Varje term svarar mot ett element i den valda raden eller kolumnen och dess minor, som fås genom att stryka bort raden och kolumnen som korresponderar med elementet, multiplicerat med $(-1)^{i+j}$ där $i$ och $j$ är rad- respektive kolumnindex för elementet. Därefter utvecklar vi längs raden med hjälp av kofaktorutveckling, vilket reducerar problemet ytterligare ett steg. Slutligen används Sarrus regel för att beräkna determinanten av en $3 \times 3$ matris.

\begin{enumerate}[left=0pt]

\item Vi ska beräkna determinanten för en $5 \times 5$ matris. För att lösa problemet kommer vi använda cofaktor expansion, där vi väljer den rad eller kolumn som har flest nollor. I detta fall är det sista raden som har flest nollor~(4). Vi har en $5 \times 5$ matris som ser ut som följer:
\[
\begin{bmatrix}
1 & 0 & 0 & 0 & 4 \\
0 & 7 & 0 & 5 & 0 \\
0 & 2 & 1 & 3 & 0 \\
0 & 6 & 0 & 8 & 0 \\
0 & 0 & 0 & 0 & 1
\end{bmatrix} 
\]

\item Sedan skriver vi ut determinanten genom att göra en summa av produkter. Vi använder den sista raden som vår utvecklingsrad, eftersom den har flest nollor. Vi får:
\begin{align*}
\begin{vmatrix}
1 & 0 & 0 & 0 & 4 \\
0 & 7 & 0 & 5 & 0 \\
0 & 2 & 1 & 3 & 0 \\
0 & 6 & 0 & 8 & 0 \\
0 & 0 & 0 & 0 & 1
\end{vmatrix} 
&= 
(0)(-1)^{5+1}
\begin{vmatrix}
0 & 0 & 0 & 4 \\
7 & 0 & 5 & 0 \\
2 & 1 & 3 & 0 \\
6 & 0 & 8 & 0
\end{vmatrix} 
+ (0)(-1)^{5+2}
\begin{vmatrix}
1 & 0 & 0 & 4 \\
0 & 0 & 5 & 0 \\
0 & 1 & 3 & 0 \\
0 & 0 & 8 & 0 \\
\end{vmatrix} 
+ (0)(-1)^{5+3}
\begin{vmatrix}
1 & 0 & 0 & 4 \\
0 & 7 & 5 & 0 \\
0 & 2 & 3 & 0 \\
0 & 6 & 8 & 0 
\end{vmatrix} \\ % <-- line break
&\quad
+ (0)(-1)^{5+4} 
\begin{vmatrix}
1 & 0 & 0 & 0 \\
0 & 7 & 0 & 5 \\
0 & 2 & 1 & 3 \\
0 & 6 & 0 & 8
\end{vmatrix}
+ (1)(-1)^{5+5} 
\begin{vmatrix}
1 & 0 & 0 & 0 \\
0 & 7 & 0 & 5 \\
0 & 2 & 1 & 3 \\
0 & 6 & 0 & 8
\end{vmatrix} \\ % <-- line break
&= 
\begin{vmatrix}
1 & 0 & 0 & 0 \\
0 & 7 & 0 & 5 \\
0 & 2 & 1 & 3 \\
0 & 6 & 0 & 8
\end{vmatrix} 
\end{align*}

Utvecklar längs rad 1:
\begin{align*}
\begin{vmatrix}
1 & 0 & 0 & 0 \\
0 & 7 & 0 & 5 \\
0 & 2 & 1 & 3 \\
0 & 6 & 0 & 8
\end{vmatrix}
&=
(1)(-1)^{1+1}
\begin{vmatrix}
7 & 0 & 5 \\
2 & 1 & 3 \\
6 & 0 & 8
\end{vmatrix}
+ (0)(-1)^{1+2} 
\begin{vmatrix}
0 & 0 & 5 \\
0 & 1 & 3 \\
0 & 0 & 8
\end{vmatrix} \\ % <-- line break
&\quad
+(0)(-1)^{1+3}
\begin{vmatrix}
0 & 7 & 5 \\
0 & 2 & 3 \\
0 & 6 & 0
\end{vmatrix}
+(0)(-1)^{1+4} 
\begin{vmatrix}
     0 & 7 & 0 \\
     0 & 2 & 1 \\
     0 & 6 & 0
\end{vmatrix} \\ % <-- line break
&= 
\begin{vmatrix}
7 & 0 & 5 \\
2 & 1 & 3 \\
6 & 0 & 8
\end{vmatrix}
\end{align*}

\item Använder Sarrus regel för att räkna ut determinanten:
\[
\begin{vmatrix}
  7&0&5 \\ 2&1&3 \\ 6&0&8
\end{vmatrix} 
\begin{matrix}
  7&0 \\ 2&1 \\ 6&0
\end{matrix} 
= ( 7\cdot 1\cdot 8) - ( 6\cdot 1\cdot 5) = 26\,.
\]

\end{enumerate}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .