[Tex/LaTex] Missing $ inserted error

errorsformattingmath-mode

All the below equations work in CodeCogs but I am still getting an error for them in Texmaker. \begin{equation} is line 501

\begin{align}
P(c)= \frac{1}{n} \sum_{i=1}^{n} P(c\vert\vec{x_i})

\mu_{c,j} = \sum_{i=1}^{n} (\frac{P(c\vert\vec{x_i})}{nP(c)})x_{i,j}

(\sum_{c})_{j,k} = \sum_{i=1}^{n}(\frac{P(c\vert\vec{x_i})}{nP(c)})(x_{i,j} - \mu_{c,j})(x_{i,k} - \mu_{c,k})

 P(c\vert\vec{x_i}) = \frac{P(\vec{x_i}\vertc)P(c))}{\sum_{i=1}^{k}P(\vec{x_i}\vertc)P(c)}

P(\vec{x_i}|c) = \frac{1}{\sqrt{2\pi(\sum_{c})}} exp(- \frac{1}{2}(\vec{x_i} - \vec{\mu_c})^T \sum_{c}^{-1}(\vec{x_i} - \vec{\mu_c}))
\end{align}

Error:

! Missing $ inserted.
<inserted text>
$
l.501

I've inserted a begin-math/end-math symbol since I think
you left one out. Proceed, with fingers crossed.
! Display math should end with $$.
<to be read again>
\par
l.501

Best Answer

Apart from the missing \\s to terminate the lines, I strongly suggest you read the amsmath package documentation.

I could not find the vertc symbol anyway, which I translated in \vert c.

Do not leave empty lines inside math;

I also manually adjusted the height of the brackets, and substituted exp with the proper operator \exp.

I also substituted (\sum_c)_{j,k} with \sum_c{\mathstrut}_{j,k} to get rid of the parenthesis

I hope to have caught everything

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align}
P(c)= \frac{1}{n} \sum_{i=1}^{n} P(c\vert\vec{x_i})\\
\mu_{c,j} = \sum_{i=1}^{n} \Bigl(\frac{P(c\vert\vec{x_i})}{nP(c)}\Bigr)x_{i,j}\\
\sum_{c}{\mathstrut}_{j,k} = \sum_{i=1}^{n}\Bigl(\frac{P(c\vert\vec{x_i})}{nP(c)}\Bigr)(x_{i,j} - \mu_{c,j})(x_{i,k} - \mu_{c,k})\\
 P(c\vert\vec{x_i}) = \frac{P(\vec{x_i}\vert c)P(c))}{\sum_{i=1}^{k}P(\vec{x_i}\vert c)P(c)}\\
P(\vec{x_i}|c) = \frac{1}{\sqrt{2\pi\sum_{c}}} \exp\Bigl(- \frac{1}{2}(\vec{x_i} - \vec{\mu_c})^T \sum_{c}^{-1}(\vec{x_i} - \vec{\mu_c})\Bigr)
\end{align}
\end{document}

enter image description here

Related Question