\begin{algorithm}
\caption{Random Vector Generation}
\begin{algorithmic}
\State Generate $\mathit{n}$ random variables $\mathit{U_{1},...,U_{n}}$ as iid variables from $\mathit{U(0,1)}$ \newline
\State Set $X_{1} = 1- X_{n},...,X_{n} = 1- 2U_{n}$ and $\mathit{R = \sum_{i=1}^n X_{i}^2}$ \newline
\State if $\mathit{R \leq 1}$, accept $\mathit{\textbf{X} = (X_{1},....X_{n})^T}$ as the desired vector; otherwise go to step 1.
\end{algorithmic}
\end{algorithm}
答案1
我不知道你是怎么得到那张照片的,因为电话
\begin{algorithmic}
相当于
\begin{algorithmic}[0]
意思是“没有行号”。你想要
\begin{algorithmic}[1]
意思是“给每行编号”。
这是有效的代码,使用了更好的技巧来\newline
分隔线条。
\documentclass{article}
\usepackage{algorithm,algpseudocode}
\begin{document}
\begin{algorithm}
\caption{Random Vector Generation}
\begin{algorithmic}[1]
\setlength{\itemsep}{1ex}
\State Generate $n$ random variables $U_{1},\dots,U_{n}$ as iid variables from
$U(0,1)$
\State Set $X_{1} = 1- 2U_{1},\dots,X_{n} = 1- 2U_{n}$ and $R = \sum_{i=1}^n X_{i}^2$
\State if $R \leq 1$, accept $\mathbf{X} = (X_{1},\dots,X_{n})^T$ as the desired vector;
otherwise go to step~1.
\end{algorithmic}
\end{algorithm}
\end{document}
请注意,我删除了所有\mathit
声明并将其转换...
为\dots
。我还修复了X_{1}=1-2U_{1}
。