4

I am new in Latex, I am trying to write the Equation below, but I have some errors, I couldn't find them. enter image description here

 \documentclass{article}  
    \usepackage{amsmath}
    \begin{document}
    \begin{equation}
    \begin{split}
    E_q_2(A,B)
    &=\frac{1}{3n}\sum_{i=1}^{n}\frac{(1-e^{{-\mu}_A(x_i)})\times(1-e^{-\mu_B(x_i)})}{{(1-e^{{-\mu}_A(x_i)})}^2+{(1-e^{-\mu_B(x_i)})}^2-[(1-e^{{-\mu}_A(x_i)})\times(1-e^{-\mu_B(x_i)})]}\\
    &+ \frac{(1-e^{-(1-v_A(x_i))})\times(1-e^{-(1-v_B(x_i))})}{{(1-e^{-(1-v_A(x_i))})}^2+{(1-e^{-(1-v_B(x_i))})}^2-[(1-e^{-(1-v_A(x_i))})\times(1-e^{-(1-v_B(x_i))})]}\\
    &+\frac{(1-e^{-\frac{1}{2}(1+\mu_A(x_i)-v_A(x_i))})\times(1-e^{-\frac{1}{2}(1+\mu_B(x_i)-v_B(x_i))})}{
    \splitfrac{{(1-e^{-\frac{1}{2}(1+\mu_A(x_i)-v_A(x_i))})}^2+{(1-e^{-\frac{1}{2}(1+\mu_B(x_i)-v_B(x_i))})}^2 -}\\
     &{[(1-e^{-\frac{1}{2}(1+\mu_A(x_i)-v_A(x_i))})\times(1-e^{-\frac{1}{2}(1+\mu_B(x_i)-v_B(x_i))})]}}
    \end{split}
    \end{equation}
    \end{document}

Edit by @koleygr: (in order of subscripts but removed \splitfrac too)

Corrected MWE:

\documentclass{article}  
\usepackage{amsmath}
\begin{document}
\begin{equation}
\begin{split}
E_{q_2}(A,B)
&=\frac{1}{3n}\sum_{i=1}^{n}\frac{(1-e^{{-\mu}_{A}(x_i)})\times(1-e^{-\mu_{B}(x_i)})}{{(1-e^{{-\mu}_{A}(x_i)})}^2+{(1-e^{-\mu_{B}(x_i)})}^2-[(1-e^{{-\mu}_{A}(x_i)})\times(1-e^{-\mu_{B}(x_i)})]}\\
&+ \frac{(1-e^{-(1-v_{A}(x_i))})\times(1-e^{-(1-v_{B}(x_i))})}{{(1-e^{-(1-v_{A}(x_i))})}^2+{(1-e^{-(1-v_{B}(x_i))})}^2-[(1-e^{-(1-v_{A}(x_i))})\times(1-e^{-(1-v_{B}(x_i))})]}\\
&+\frac{(1-e^{-\frac{1}{2}(1+\mu_{A}(x_i)-v_{A}(x_i))})\times(1-e^{-\frac{1}{2}(1+\mu_{B}(x_i)-v_{B}(x_i))})}{
{(1-e^{-\frac{1}{2}(1+\mu_{A}(x_i)-v_{A}(x_i))})}^2+{(1-e^{-\frac{1}{2}(1+\mu_{B}(x_i)-v_{B}(x_i))})}^2 -[(1-e^{-\frac{1}{2}(1+\mu_{A}(x_i)-v_{A}(x_i))})\times(1-e^{-\frac{1}{2}(1+\mu_{B}(x_i)-v_{B}(x_i))})]}
\end{split}
\end{equation}
\end{document}
2
  • 2
    Welcome to TeX.SX! Your code has problems (errors) because you are using terms like \mu_A(x_i) that should be \mu_{A}(x_i) (or \mu_{A(xi)} -added this to make you understand that TeX doesn't know how to behave on this situation). The curly brackets are really needed there for TeX to recognize what exactly of all this stuff is the subscript. Also, there are some commands came from a package you haven't add in your MWE (at least \splitfrac). Finally, to break such a function, the best way is to declare other functions like E(A,x_i)=\left(1-\mu_{A}(x_i)-v_{A}(x_i)\right) and go on ...
    – koleygr
    Mar 17, 2019 at 8:52
  • 3
    The calculations, could be done by multiplying/adding etc the functions that you declared and will give other functions you can name again. Then even in the final fraction you could have the functions you have declared in any of the steps and even in the case it still could not fit (in your MWE it can), you could write your denominator like \left(\begin{array}{@{}l@{}l@{}}<First Term> & <Some Terms>\\&<Rest of the terms>\end{array}\right).
    – koleygr
    Mar 17, 2019 at 9:00

3 Answers 3

5

If I were writing it, I would use something like

demo

\documentclass{article}  
\usepackage{mathtools}
\begin{document}
\begin{equation}
E_{q_2}(A,B) = \frac{1}{3n}\sum_{i=1}^{n} \left( \frac{P_1(x_i)}{Q_1(x_i)}
    + \frac{P_2(x_i)}{Q_2(x_i)} + \frac{P_3(x_i)}{Q_3(x_i)} \right)
\end{equation}
where 
\addtocounter{equation}{-1}%
\begin{subequations}
\begin{align}
P_1(x_i) &= \left(1-e^{{-\mu}_{A}(x_i)}\right)\left(1-e^{-\mu_{B}(x_i)}\right)\\
Q_1(x_i) &= \left(1-e^{{-\mu}_{A}(x_i)}\right)^2+\left(1-e^{-\mu_{B}(x_i)}\right)^2 \notag\\
  &\quad - \left(1-e^{{-\mu}_{A}(x_i)}\right)\left(1-e^{-\mu_{B}(x_i)}\right)\\
P_2(x_i) &= \left(1-e^{-(1-v_{A}(x_i))}\right)\left(1-e^{-(1-v_{B}(x_i))}\right)\\
Q_2(x_i) &= \left(1-e^{-(1-v_{A}(x_i))}\right)^2+\left(1-e^{-(1-v_{B}(x_i))}\right)^2 \notag\\
  &\quad - \left(1-e^{-(1-v_{A}(x_i))}\right)\left(1-e^{-(1-v_{B}(x_i))}\right)\\
P_3(x_i) &= \left(1-e^{-\frac{1}{2}(1+\mu_{A}(x_i)-v_{A}(x_i))}\right)
    \left(1-e^{-\frac{1}{2}(1+\mu_{B}(x_i)-v_{B}(x_i))}\right)\\
\shortintertext{and}
Q_3(x_i) &= \left(1-e^{-\frac{1}{2}(1+\mu_{A}(x_i)-v_{A}(x_i))}\right)^2
    +\left(1-e^{-\frac{1}{2}(1+\mu_{B}(x_i)-v_{B}(x_i))}\right)^2 \notag\\
  &\quad - \left(1-e^{-\frac{1}{2}(1+\mu_{A}(x_i)-v_{A}(x_i))}\right)
    \left(1-e^{-\frac{1}{2}(1+\mu_{B}(x_i)-v_{B}(x_i))}\right)
\end{align}
\end{subequations}

\end{document}
3
  • An excellent point, I also wanted to suggest to rewrite in order to remove visual clutter. Mar 18, 2019 at 18:26
  • @OlegLobachev - It also occurred to be that one could replace x_i with x in (1a) though (1f). Maybe later. Mar 19, 2019 at 0:08
  • Thank you John Kormylo. This solution also works fine.
    – Noor
    Mar 19, 2019 at 18:24
5

(this answer is based on the code provided in the "Corrected MWE" above.)

I suggest you load the mathtools package and use several \splitdfrac and \splitfrac instructions; see below for an application of this idea. Second, I would replace the e^{...} notation with \exp(...), as otherwise it's not easy to read the second-level superscript material. Third, I would use \bigl and \bigr to increase the sizes of some (but certainly not all) round parentheses and square brackets.

enter image description here

\documentclass{article}  
\usepackage{mathtools} % for '\splitfrac' macro
\DeclareMathOperator{\E}{E} % expectations operator
\begin{document}
\begin{align}
\E_{q_2}(A,B)
&=\frac{1}{3n}\sum_{i=1}^{n}
\frac{\bigl[1-\exp\bigl(-\mu_{\!A}(x_i)\bigr)\bigr]\times
      \bigl[1-\exp\bigl(-\mu_{\!B}(x_i)\bigr)\bigr]}{%
 \biggl(\splitdfrac{%
 \bigl[1-\exp\bigl(-\mu_{\!A}(x_i)\bigr)\bigr]^2
+\bigl[1-\exp\bigl(-\mu_{\!B}(x_i)\bigr)\bigr]^2}{%
-\bigl[1-\exp\bigl(-\mu_{\!A}(x_i)\bigr)\bigr]\times
       \bigl[1-\exp\bigl(-\mu_{\!B}(x_i)\bigr)\bigr]}
 \biggr)} \notag\\[1ex]
&+\frac{\bigl[1-\exp\bigl(-(1-v_{\!A}(x_i))\bigr)\bigr]\times
        \bigl[1-\exp\bigl(-(1-v_{\!B}(x_i))\bigr)\bigr]}{%
 \biggl(\splitdfrac{%
  \bigl[1-\exp\bigl(-(1-v_{\!A}(x_i))\bigr)\bigr]^2
 +\bigl[1-\exp\bigl(-(1-v_{\!B}(x_i))\bigr)\bigr]^2}{%
 -\bigl[1-\exp\bigl(-(1-v_{\!A}(x_i))\bigr)\bigr]\times
         \bigl[1-\exp\bigl(-(1-v_{\!B}(x_i))\bigr)\bigr]}
 \biggr)} \notag\\[1ex]
&+\frac{%
 \biggl(\splitdfrac{%
   \bigl[1-\exp\bigl(-\frac{1}{2}(1+\mu_{\!A}(x_i)-v_{\!A}(x_i))\bigr)\bigr]}{%
   \times
   \bigl[1-\exp\bigl(-\frac{1}{2}(1+\mu_{\!B}(x_i)-v_{\!B}(x_i))\bigr)\bigr]}
 \biggr)}{%
 \left(\splitdfrac{%
   \splitfrac{%
   \bigl[1-\exp\bigl(-\frac{1}{2}(1+\mu_{\!A}(x_i)-v_{\!A}(x_i))\bigr)\bigr]^2}{%
  +\bigl[1-\exp\bigl(-\frac{1}{2}(1+\mu_{\!B}(x_i)-v_{\!B}(x_i))\bigr)\bigr]^2}}{% 
   \splitfrac{%
   {}-{} % make this a binary rather than a unary operator... 
    \bigl[1-\exp\bigl(-\frac{1}{2}(1+\mu_{\!A}(x_i)-v_{\!A}(x_i))\bigr)\bigr]}{
    \times
    \bigl[1-\exp\bigl(-\frac{1}{2}(1+\mu_{\!B}(x_i)-v_{\!B}(x_i))\bigr)\bigr]}}
 \right)}
\end{align}
\end{document}
1
  • Thanks Mico,it works fine.
    – Noor
    Mar 18, 2019 at 9:57
3

I have edited @mico's code to make it a bit shorter.

\documentclass{article}  
\usepackage{mathtools} % for '\splitfrac' macro
\DeclareMathOperator{\E}{E} % expectations operator
\DeclarePairedDelimiter{\parens}()
\DeclarePairedDelimiter{\sparens}[]

\newcommand{\myexp}[1]{\exp\parens[\big]{#1}}
\newcommand{\ome}[1]{\sparens[\big]{1-\myexp{#1}}}

\begin{document}
\begin{align}
\E_{q_2}(A,B)
&=\frac{1}{3n}\sum_{i=1}^{n}
\frac{\ome{-\mu_{\!A}(x_i)}\times
      \ome{-\mu_{\!B}(x_i)}}{%
 \biggl(\splitdfrac{%
 \ome{-\mu_{\!A}(x_i)}^2
+\ome{-\mu_{\!B}(x_i)}^2}{%
-\ome{-\mu_{\!A}(x_i)}\times
       \ome{-\mu_{\!B}(x_i)}}\biggr)} \notag\\[1ex]
&+\frac{\ome{-(1-v_{\!A}(x_i))}\times
        \ome{-(1-v_{\!B}(x_i))}}{%
 \biggl(\splitdfrac{%
  \ome{-(1-v_{\!A}(x_i))}^2
 +\ome{-(1-v_{\!B}(x_i)))}^2}{%
 -\bigl\{\ome{-(1-v_{\!A}(x_i))}\times
         \ome{-(1-v_{\!B}(x_i))}\bigr\}}
 \biggr)} \notag\\[1ex]
&+\frac{%
 \biggl(\splitdfrac{%
   \ome{-\frac{1}{2}(1+\mu_{\!A}(x_i)-v_{\!A}(x_i))}}{%
   \times
   \ome{-\frac{1}{2}(1+\mu_{\!B}(x_i)-v_{\!B}(x_i))}}
 \biggr)}{%
 \left(\splitdfrac{%
   \splitfrac{%
   \ome{-\frac{1}{2}(1+\mu_{\!A}(x_i)-v_{\!A}(x_i))}^2}{%
  +\ome{-\frac{1}{2}(1+\mu_{\!B}(x_i)-v_{\!B}(x_i))}^2}}{% 
   \splitfrac{%
   -\ome{-\frac{1}{2}(1+\mu_{\!A}(x_i)-v_{\!A}(x_i))}}{
    \times
    \ome{-\frac{1}{2}(1+\mu_{\!B}(x_i)-v_{\!B}(x_i))}\bigr\} }}
 \right)}
\end{align}
\end{document}

And, with smaller margins the code can be further sanitized:

\documentclass{article}  
\usepackage[margin=1in]{geometry}
\usepackage{mathtools} % for '\splitfrac' macro
\DeclareMathOperator{\E}{E} % expectations operator
\DeclarePairedDelimiter{\parens}()
\DeclarePairedDelimiter{\sparens}[]

\newcommand{\myexp}[1]{\exp\parens[\big]{#1}}
\newcommand{\ome}[1]{\sparens[\big]{1-\myexp{#1}}}

\newcommand{\rat}[2]{%
\frac{\ome{#1} \times \ome{#2}}{
\parens[\bigg]{\splitdfrac{\ome{#1}^2 + \ome{#2}^2}{- \ome{#1}\times \ome{#2}}}}
}


\begin{document}
\begin{multline}
\E_{q_2}(A,B)
=\frac{1}{3n}\sum_{i=1}^{n}
\rat{-\mu_{\!A}(x_i)}{-\mu_{\!B}(x_i)}
\\
+\rat{-(1-v_{\!A}(x_i))}{-(1-v_{\!B}(x_i))}\\
+
 \rat{-\frac{1}{2}(1+\mu_{\!A}(x_i)-v_{\!A}(x_i))}{%
   {-\frac{1}{2}(1+\mu_{\!B}(x_i)-v_{\!B}(x_i))}}.
\end{multline}
\end{document}
4
  • 2
    @JPi (+1): You have got a new privilege! Congratulations.
    – user156344
    Mar 17, 2019 at 15:33
  • 2
    +1. Congrats on passing the 10k rep mark! I thought about assuming narrower margins (and hence a wider text block) as well, but didn't bring it up since this piece of information was not contained in the original query.
    – Mico
    Mar 17, 2019 at 15:41
  • 2
    Thanks @Mico.... Of course! My point was mainly to demonstrate that code that is repeated can be shortened.
    – JPi
    Mar 17, 2019 at 15:43
  • 1
    @JPi Congratulations also by me.
    – Sebastiano
    Mar 17, 2019 at 22:01

You must log in to answer this question.

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