我有以下等式:
\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}
结果如下:
我坚持认为使用 align 可以解决这个问题,这是我尝试过的:
\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}
现在结果发生了变化!我的问题是,尽管开始了新的一行,如何对齐方程式?
答案1
不太清楚您喜欢如何格式化您的方程式...像这样?
\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}
答案2
正如侧面的相关链接所示(比如这个https://tex.stackexchange.com/a/74822/132800),每行都必须放置对齐字符。对于您的情况,
\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}