[Tex/LaTex] Align two equations in latex

equations

I have the following equations :

    \begin{equation}\label{eq:4: Partial  W }
      \begin{align}
\frac{\partial s}
     {\partial W}
    & = \frac{\partial \sum_{i=1}^{n} (y_i -(W\cdot x_i+b))^2}
                         {\partial W}\\
    & = \sum_{i=1}^{n} 2(y_i -W\cdot x_i-b)\cdot(-x_i))
    = 2\cdot \sum_{i=1}^{n} (-y_i\cdot x_i + W\cdot x_i^2 + b\cdot x_i )  \stackrel{!}{=} 0    \\ \\
    &\Longleftrightarrow W\cdot(\sum_{i=1}^{n} x_i^2) + b\cdot(\sum_{i=1}^{n}x_i) = \sum_{i=1}^{n}x_i\cdot y_i
  \end{align}
\end{equation}
\begin{equation}\label{eq:5: Partial  b }
      \begin{align}
\frac{\partial s}
     {\partial b}
    & = \frac{\partial \sum_{i=1}^{n} (y_i -(W\cdot x_i+b))^2}
                         {\partial b}\\
    & = \sum_{i=1}^{n} 2(y_i -W\cdot x_i-b)\cdot(-1))
    = 2\cdot \sum_{i=1}^{n} (-y_i\cdot+ W\cdot x_i+ b)  \stackrel{!}{=} 0    \\ \\
    &\Longleftrightarrow W\cdot(\sum_{i=1}^{n} x_i) +\sum_{i=1}^{n}b = \sum_{i=1}^{n} y_i\\
    &\Longleftrightarrow W\cdot(\sum_{i=1}^{n}x_i) + n\cdot b = \sum_{i=1}^{n} y_i
  \end{align}
\end{equation}

the result looks as followed :
enter image description here

My question is how may align the 2nd equation, and put both equation IDs at the end of each one and not the middle .

Best Answer

Put everything in one align environment, don't enclose this in an equation environment, and use \nonumber on lines that should not be numbered.

\documentclass{article}
\usepackage{mathtools}
\begin{document}
\begin{align}
\frac{\partial s}{\partial W}
&= \frac{\partial \sum_{i=1}^{n} (y_i -(W\cdot x_i+b))^2}
                    {\partial W} \nonumber \\
&= \sum_{i=1}^{n} 2(y_i -W\cdot x_i-b)\cdot(-x_i))
 = 2\cdot \sum_{i=1}^{n} (-y_i\cdot x_i + W\cdot x_i^2 + b\cdot x_i )  
   \stackrel{!}{=} 0    \nonumber\\ \nonumber\\
&\Longleftrightarrow W\cdot(\sum_{i=1}^{n} x_i^2) + b\cdot(\sum_{i=1}^{n}x_i) 
 = \sum_{i=1}^{n}x_i\cdot y_i \label{eq:4: Partial  W } \\
\frac{\partial s}{\partial b}
&= \frac{\partial \sum_{i=1}^{n} (y_i -(W\cdot x_i+b))^2}
                    {\partial b} \nonumber \\
&= \sum_{i=1}^{n} 2(y_i -W\cdot x_i-b)\cdot(-1))
 = 2\cdot \sum_{i=1}^{n} (-y_i\cdot+ W\cdot x_i+ b)  
   \stackrel{!}{=} 0    \nonumber \\ \nonumber \\
&\Longleftrightarrow W\cdot(\sum_{i=1}^{n} x_i) +\sum_{i=1}^{n}b 
 = \sum_{i=1}^{n} y_i \nonumber \\
&\Longleftrightarrow W\cdot(\sum_{i=1}^{n}x_i) + n\cdot b 
 = \sum_{i=1}^{n} y_i \label{eq:5: Partial  b }
\end{align}
\end{document}

enter image description here

Related Question