3

I've the following equation :

    \begin{equation}\label{eq:5}
  \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 + a \cdot x_i + b )  \stackrel{!}{=} 0} \\

   \Longleftrightarrow a\cdot (\sum_{i=1}^{n} x_i) + \sum_{i=1}^{n}b = \sum_{i=1}^{n} y_i

   \Longleftrightarrow a\cdot (\sum_{i=1}^{n} x_i) + n \cdot b = \sum_{i=1}^{n}y_i
\end{equation}

and here how the result looks like :

enter image description here

I tough that using align would solve the issue here is what I've tried:

    \begin{equation}\label{eq:5}
  \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 + a \cdot x_i + b )  \stackrel{!}{=} 0} \\

   \Longleftrightarrow a\cdot (\sum_{i=1}^{n} x_i) + \sum_{i=1}^{n}b = \sum_{i=1}^{n} y_i

   \Longleftrightarrow a\cdot (\sum_{i=1}^{n} x_i) + n \cdot b = \sum_{i=1}^{n}y_i


 \end{align}
\end{equation}

There is now change in the result ! My question is how to align the equation despite starting a new line ?

Torbjørn T.
  • 206,688
Engine
  • 175
  • Proper use of alignment characters. You have to add the alignment character & in each line. Equations will be aligned relative to the alignment character(s). – Huang_d Jun 07 '17 at 12:43
  • @Huang_d can you write an example because I've aligned '&' without any change ! – Engine Jun 07 '17 at 12:49
  • You can't have empty lines inside a display math environment, and you can't have an align environment inside an equation environment. Both will throw errors. – Torbjørn T. Jun 07 '17 at 12:54
  • @TorbjørnT. is there no way to align them ? – Engine Jun 07 '17 at 12:56
  • I didn't say there is no way to align them, I merely pointed out a couple of obvious mistakes in your code. – Torbjørn T. Jun 07 '17 at 14:18

2 Answers2

5

It is not very clear how you like format your equations ... Like this?

![enter image description here

\documentclass{article}
\usepackage{mathtools}

\begin{document}
\begin{equation}\label{eq:5}
    \begin{split}
\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 + a \cdot x_i + b )  \stackrel{!}{=} 0    \\
    &   \Longleftrightarrow a\cdot \sum_{i=1}^{n} x_i + \sum_{i=1}^{n}b = \sum_{i=1}^{n} y_i  \\
    &   \Longleftrightarrow a\cdot \sum_{i=1}^{n} x_i + n \cdot b = \sum_{i=1}^{n}y_i
    \end{split}
\end{equation}
\end{document}
Zarko
  • 296,517
2

As related links on the side indicate (such as this one https://tex.stackexchange.com/a/74822/132800 ), alignment characters have to be put on each line. In your case,

\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 + a \cdot x_i + b )  \stackrel{!}{=} 0} \\
\Longleftrightarrow& a\cdot (\sum_{i=1}^{n} x_i) + \sum_{i=1}^{n}b = \sum_{i=1}^{n} y_i\\
\Longleftrightarrow& a\cdot (\sum_{i=1}^{n} x_i) + n \cdot b = \sum_{i=1}^{n}y_i
\end{align}
Huang_d
  • 1,797