有人能告诉我如何在 latex 中以算法格式编写这个吗?p-37,38。谢谢。
https://uwspace.uwaterloo.ca/bitstream/handle/10012/11017/Maki_Erik.pdf?sequence=3&isAllowed=y
答案1
enumerate
这是使用环境和amsmath
命令包完成的\dotsc
。我还添加了标签和参考,尽管对于这么小的东西,您可以手动输入数字。
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{enumerate}
\item Select \(x_0 \in X\)
\item Calculate \(\mathbf{p}(x_0) = (p_1(x_0), p_2(x_0), \dotsc, p_N(x_0))\)
\item Select \(w_{\sigma_1} \in \{1, \dotsc, N\}\)
according to the probabilities, \(\mathbf{p}(x_0)\)
\item \label{step 4} Apply \(w_{\sigma_1}\), \(x_1 = w_{\sigma_1}(x_0)\)
\item Repeat this process using \(x_n = w_{\sigma_n}(x_{n-1})\)
(calculated in Step \ref{step 4}) as the new \(x_0\).
\end{enumerate}
\end{document}
编辑
algorithm
也可以使用包的环境来完成此操作algorithm2e
,如下所示:
\documentclass{article}
\usepackage[ruled]{algorithm2e}
\usepackage{amsmath}
\SetNlSty{}{}{.}
\begin{document}
\begin{algorithm}
\nl Select \(x_0 \in X\)
\nl Calculate \(\mathbf{p}(x_0) = (p_1(x_0), p_2(x_0), \dotsc, p_N(x_0))\)
\nl Select \(w_{\sigma_1} \in \{1, \dotsc, N\}\)
according to the probabilities, \(\mathbf{p}(x_0)\)
\nl Apply \(w_{\sigma_1}\), \(x_1 = w_{\sigma_1}(x_0)\)
\nl Repeat this process using \(x_n = w_{\sigma_n}(x_{n-1})\)
(calculated in Step 4) as the new \(x_0\).
\caption{An Algorithm}
\end{algorithm}
\end{document}