5

Writing an equation in LaTeX

How can I write this equation in LaTeX? I am getting an error:

missing inserted $

C(Z)=\frac{-0.5002\,  (+/- 0.1000)\,  z^-1 + 2.161 \, (+/- 0.1821) \, z^-2 - 1.744 \, (+/- 0.1489)\,  z^-3 - 2.138 \, (

              +/- 0.2009)\,  z^-4 + 2.0073 \, (+/- 0.2002) \, z^-5 + 1.047 (+/- 0.1986)\,  z^-6 - 1.124 (

              +/- 0.1978) \, z^-7 - 2.1009 \, (+/- 0.2176)\,  z^-8 + 0.1732 \, (+/- 0.1959)\,  z^-9 + 2.305 (

              +/- 0.2109)\,  z^-10 + 0.7807 \, (+/- 0.1846) \, z^-11 - 1.436 \, (+/- 0.225) \, z^-12 - 2.605 (

              +/- 0.2003) \, z^-13 + 2.405 \, (+/- 0.2306) \, z^-14 + 1.517 (+/- 0.1872)\,  z^-15 - 2.244 (

                                                   +/- 0.1778) \, z^-16 + 0.6634 (+/- 0.05466) \, z^-19

      }{1 - 2.738 (+/- 0.07274) z^-1 + 1.241 (+/- 0.2085) z^-2 + 1.997 (+/- 0.1935) z^-3

              - 1.033 (+/- 0.2873) z^-6 - 0.2646 (+/- 0.3029) z^-5 - 1.415 (+/- 0.2352) z^-6

              + 0.4815 (+/- 0.2701) z^-8 + 1.313 (+/- 0.249) z^-8 + 0.3993 (+/- 0.2877) z^-9

              - 0.7446 (+/- 0.2492) z^-10 - 1.7777(+/- 0.2392) z^-11 + 1.443 (+/- 0.2471) z^-12

              - 1.054 (+/- 0.2877) z^-13 + 0.7(+/- 0.277719) z^-14 + 1.47 (+/- 0.1926) z^-15

                                           - 1.847 (+/- 0.20771) z^-16 + 0.6023 (+/- 0.06359) z^-17}
2
  • 6
    You are not allowed to use blank line in math modes. If you remove all the blank lines in your equation, your missing inserted $ error will disappear.
    – KersouMan
    Nov 21, 2019 at 11:08
  • 4
    Moreover, you might want to use \pm instead of +/- and to wrap all your exponents inside curly braces (e.g. z^{-2} instead of z^-2) to avoid having a minus sign as exponent and the number inline with the z.
    – KersouMan
    Nov 21, 2019 at 11:24

4 Answers 4

16

Some suggestions and observations (some already made by @KersouMan):

  • Don't provide all-blank lines in a display math environment

  • Write \pm rather than +/-

  • Encase the exponent terms in curly braces, i.e., write z^{-19} rather than z^-19

  • Since the numerator and denominator contain 17 and 18 separate additive terms, respectively, using conventional \frac notation cannot possibly work. I suggest you list the numerator and denominator separately.

enter image description here

\documentclass{article}
\usepackage{mathtools}
\newcommand{\mybox}[1]{\parbox[t]{0.75\textwidth}{\raggedright$\displaystyle #1$}}
\begin{document}

\begin{align*}
C(Z)&=\frac{U(Z)}{V(Z)}\,,\\
\shortintertext{where}
U(z)&=\mybox{ -0.5002 (\pm 0.1000)\,z^{-1} + 2.161 (\pm 0.1821)\,z^{-2} 
              -1.744  (\pm 0.1489)\,z^{-3} - 2.138 (\pm 0.2009)\,z^{-4} 
              +2.0073 (\pm 0.2002)\,z^{-5} + 1.047 (\pm 0.1986)\,z^{-6} 
              -1.124  (\pm 0.1978)\,z^{-7} - 2.1009(\pm 0.2176)\,z^{-8} 
              +0.1732 (\pm 0.1959)\,z^{-9} + 2.305 (\pm 0.2109)\,z^{-10} 
              +0.7807 (\pm 0.1846)\,z^{-11}- 1.436 (\pm 0.225 )\,z^{-12} 
              -2.605  (\pm 0.2003)\,z^{-13}+ 2.405 (\pm 0.2306)\,z^{-14} 
              +1.517  (\pm 0.1872)\,z^{-15}- 2.244 (\pm 0.1778)\,z^{-16} 
              +0.6634 (\pm 0.05466)\,z^{-19}}\\
\shortintertext{and} 
V(Z)&=\mybox{1-2.738  (\pm 0.07274)\,z^{-1}+ 1.241 (\pm 0.2085)\,z^{-2} 
              +1.997  (\pm 0.1935)\,z^{-3} - 1.033 (\pm 0.2873)\,z^{-4} 
              -0.2646 (\pm 0.3029)\,z^{-5} - 1.415 (\pm 0.2352)\,z^{-6} 
              +0.4815 (\pm 0.2701)\,z^{-8} + 1.313 (\pm 0.249 )\,z^{-8} 
              +0.3993 (\pm 0.2877)\,z^{-9} - 0.7446(\pm 0.2492)\,z^{-10} 
              -1.7777 (\pm 0.2392)\,z^{-11}+ 1.443 (\pm 0.2471)\,z^{-12} 
              -1.054  (\pm 0.2877)\,z^{-13}+ 0.7   (\pm 0.277719)\,z^{-14} 
              +1.47   (\pm 0.1926)\,z^{-15}- 1.847 (\pm 0.20771)\,z^{-16} 
              +0.6023 (\pm 0.06359)\,z^{-17}\,.}
\end{align*}

\end{document}
2
  • One case error: U(z) should be U(Z).
    – TRiG
    Nov 22, 2019 at 14:31
  • @TRiG -- I was wondering when the typo would get pointed out...
    – Mico
    Nov 22, 2019 at 15:56
7

In the same vein as Mico's fine answer, I propose also to do other alignments, in order to get a better overall view.

\documentclass{article}
\usepackage{mathtools,array}
\newcommand{\mybox}[1]{\parbox[t]{0.75\textwidth}{\raggedright$\displaystyle #1$}}
\begin{document}

\begin{align*}
C(Z)&=\frac{U(Z)}{V(Z)},\\
\shortintertext{where}
U(z)&=
  \begin{array}[t]{*{2}{ @{}>{{}}l@{}>{(}l<{)}@{\,}l } @{}}
  -0.5002 & \pm 0.1000  & z^{-1}  & + 2.161  & \pm 0.1821 & z^{-2} \\ 
  -1.744  & \pm 0.1489  & z^{-3}  & - 2.138  & \pm 0.2009 & z^{-4} \\ 
  +2.0073 & \pm 0.2002  & z^{-5}  & + 1.047  & \pm 0.1986 & z^{-6} \\ 
  -1.124  & \pm 0.1978  & z^{-7}  & - 2.1009 & \pm 0.2176 & z^{-8} \\ 
  +0.1732 & \pm 0.1959  & z^{-9}  & + 2.305  & \pm 0.2109 & z^{-10} \\ 
  +0.7807 & \pm 0.1846  & z^{-11} & - 1.436  & \pm 0.225  & z^{-12} \\ 
  -2.605  & \pm 0.2003  & z^{-13} & + 2.405  & \pm 0.2306 & z^{-14} \\ 
  +1.517  & \pm 0.1872  & z^{-15} & - 2.244  & \pm 0.1778 & z^{-16} \\ 
  +0.6634 & \pm 0.05466 & z^{-19} 
  \end{array}
\\
\shortintertext{and} 
V(Z)&=1
  \begin{array}[t]{*{2}{ @{}>{{}}l@{}>{(}l<{)}@{\,}l } @{}}
  -2.738  & \pm 0.07274 & z^{-1}  & + 1.241  & \pm 0.2085   & z^{-2} \\ 
  +1.997  & \pm 0.1935  & z^{-3}  & - 1.033  & \pm 0.2873   & z^{-4} \\ 
  -0.2646 & \pm 0.3029  & z^{-5}  & - 1.415  & \pm 0.2352   & z^{-6} \\ 
  +0.4815 & \pm 0.2701  & z^{-8}  & + 1.313  & \pm 0.249    & z^{-8} \\ 
  +0.3993 & \pm 0.2877  & z^{-9}  & - 0.7446 & \pm 0.2492   & z^{-10} \\ 
  -1.7777 & \pm 0.2392  & z^{-11} & + 1.443  & \pm 0.2471   & z^{-12} \\ 
  -1.054  & \pm 0.2877  & z^{-13} & + 0.7    & \pm 0.277719 & z^{-14} \\ 
  +1.47   & \pm 0.1926  & z^{-15} & - 1.847  & \pm 0.20771  & z^{-16} \\ 
  +0.6023 & \pm 0.06359 & z^{-17}\makebox[0pt][l]{.}
  \end{array}
\end{align*}

\end{document}

enter image description here

2

As your original proposal. Maybe not so aesthetic, but it also works.

enter image description here

\documentclass{article}
\usepackage{mathtools}
\usepackage[usestackEOL]{stackengine}
\stackMath

\begin{document}

\[
C(Z)=\frac{
\Longstack[l]{-0.5002 (\pm 0.1000)\,z^{-1} + 2.161 (\pm 0.1821)\,z^{-2} 
                -1.744 (\pm 0.1489)\,z^{-3} - 2.138 (\pm 0.2009)\,z^{-4} \\
                +2.0073 (\pm 0.2002)\,z^{-5} + 1.047 (\pm 0.1986)\,z^{-6} 
                -1.124  (\pm 0.1978)\,z^{-7} - 2.1009(\pm 0.2176)\,z^{-8} \\
                +0.1732 (\pm 0.1959)\,z^{-9} + 2.305 (\pm 0.2109)\,z^{-10} 
                +0.7807 (\pm 0.1846)\,z^{-11}- 1.436 (\pm 0.225 )\,z^{-12} \\
                -2.605  (\pm 0.2003)\,z^{-13}+ 2.405 (\pm 0.2306)\,z^{-14} 
                +1.517  (\pm 0.1872)\,z^{-15}- 2.244 (\pm 0.1778)\,z^{-16} \\ 
                +0.6634 (\pm 0.05466)\,z^{-19}}
                }
                {
\Longstack[l]{1-2.738  (\pm 0.07274)\,z^{-1}+ 1.241 (\pm 0.2085)\,z^{-2} 
              +1.997  (\pm 0.1935)\,z^{-3} - 1.033 (\pm 0.2873)\,z^{-4} \\
              -0.2646 (\pm 0.3029)\,z^{-5} - 1.415 (\pm 0.2352)\,z^{-6} 
              +0.4815 (\pm 0.2701)\,z^{-8} + 1.313 (\pm 0.249 )\,z^{-8} \\
              +0.3993 (\pm 0.2877)\,z^{-9} - 0.7446(\pm 0.2492)\,z^{-10} 
              -1.7777 (\pm 0.2392)\,z^{-11}+ 1.443 (\pm 0.2471)\,z^{-12} \\
              -1.054  (\pm 0.2877)\,z^{-13}+ 0.7   (\pm 0.277719)\,z^{-14} 
              +1.47   (\pm 0.1926)\,z^{-15}- 1.847 (\pm 0.20771)\,z^{-16} \\
              +0.6023 (\pm 0.06359)\,z^{-17}}
              }
\]

\end{document}
1

Don't try to put all of that stuff in the equation. Instead, write the numerator and denominator as a summation, and put the coefficients and error estimates in a table.

\begin{equation}
C(z) = \frac{\sum_{i=1}^{19} a_i z^{-i}}{1 + \sum_{i=1}^{17} b_i z^{-i}}.
\end{equation}
The coefficients $a_i$ and $b_i$ are given with their error estimates in
Table~\ref{tbl:coefs}.

Not only will this be easier to read and understand than any of the suggestions that include the coefficients in the equation, having the coefficients in a table makes it easier to extract them for someone wanting to do the calculation. Some journals will even automatically generate a csv file that can be downloaded separately from the article text.

You must log in to answer this question.

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