# combine equations

I'm trying to add the moving average equation, but keep getting errors saying: 1. missing $inserted 2. runaway argument? 3. missing } 4. undefined control sequence despite the error my equation does show up, but give me me alot of errors in the log \centering \overline{P}SM= \frac{PM + PM-1 + ...+PM -(n-1)} {{n}\frac{n}} $$\frac{1}{n} = \sum_{i=0}^{n-1} PM-i$$ \label{Movingavg  I want it to look like this: • try inserting the \overline.......} inside $...\$ if you prefer inline math, or encapsulate it within $...$ if you prefer display styled equation. And, you can remove the \centering before the math, if you would prefer the display style. Also, next time please post a MWE. The errors are because of the fact that you are using math outside it's designated environments. And, remove the \frac{n} or add the denominator part of fraction \frac{num}{den}. Commented Nov 1, 2018 at 19:20

Is this what you want, per chance?

\documentclass{article}%
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{mathtools}

\begin{document}

\begin{gather}
\overline{\!P}SM= \frac{PM + PM-1 + ...+PM -(n-1)} {n} \\
\frac{1}{n} = \sum_{i=0}^{n-1} PM-i
\end{gather}

\end{document}


You need something like this:

\begin{aligned} \overline{p}_\text{SM} &= \frac {p_M + p_{M-1} + \cdots + p_{M-(n-1)}}{n}\\ &= \frac 1n \sum_{i=0}^{n-1} p_{M-i} \end{aligned}


Notes:

• the SM is an abbrev. for simple moving average, so it is better written in text mode
• all subscripts _M through _{M-i} are written using the underscore _ they are not multiplied by p
• the two lines can be aligned at = and combined using the aligned construct
• the \frac{1}{n} can be reduced as \frac1n
• as a final note, you may want to lower the subscripts a bit more to be clear, this can be easily done by adding an extra empty ^{} like this: p_M^{} + p_{M-1}^{} + \cdots + ..., etc., which would output: