如何向算法中编号步骤添加子步骤,如图所示:
\documentclass{article}
\usepackage{algorithm,algpseudocode}
\begin{document}
\begin{algorithm}
\caption{Square Root Cubature Kalman Filter SRCKF}
\textbf{Time update}
\begin{algorithmic}[1]
\State Factorize the state error covariance matrix
\begin{equation}
P_{k-1|k-1} = S_{k-1|k-1}S_{k-1|k-1}^T
\end{equation}
\State Evaluate the cubature points (i=1,2,...,$m = 2n_x$)
\begin{equation}
X_{i,k-1|k-1} = \hat{x}_{k-1|k-1} + S_{i,k-1|k-1}\zeta_i
\end{equation}
\State Evaluate the propagated cubature points through the process equation (i=1,2,...,$m = 2n_x$)
\begin{equation}
X_{i,k|k-1}^*=f(X_{i,k-1|k-1},u_{k-1})
\end{equation}
\State Estimate the predicted state
\State Estimate the predicted error covariance
\begin{equation}
P_{k|k-1}=\frac{1}{m}\sum_{i=1}^m{X_{i,k|k-1}^*X_{i,k|k-1}^{*T}}-\hat{x}_{k|k-1}\hat{x}_{k|k-1}^T+Q_{k-1}
\end{equation}
\end{algorithmic}
\end{algorithm}
\end{document}
答案1
您可以使用类似列表的环境,algsubstates
如我在下面定义的。枚举格式与常规格式相匹配\State
(使用\footnotesize
):
\documentclass{article}
\usepackage{algorithm,algpseudocode}
\newcounter{algsubstate}
\renewcommand{\thealgsubstate}{\alph{algsubstate}}
\newenvironment{algsubstates}
{\setcounter{algsubstate}{0}%
\renewcommand{\State}{%
\stepcounter{algsubstate}%
\Statex {\footnotesize\thealgsubstate:}\space}}
{}
\begin{document}
\begin{algorithm}
\caption{Square Root Cubature Kalman Filter SRCKF}
\textbf{Time update}
\begin{algorithmic}[1]
\State Factorize the state error covariance matrix
\begin{equation}
P_{k-1 \mid k-1} = S_{k-1 \mid k-1} S_{k-1 \mid k-1}^T
\end{equation}
\State Evaluate the cubature points ($i = 1,2,\ldots,m = 2n_x$)
\begin{equation}
X_{i,k-1 \mid k-1} = \hat{x}_{k-1 \mid k-1} + S_{i,k-1 \mid k-1} \zeta_i
\end{equation}
\State Evaluate the propagated cubature points through the process equation ($i = 1,2,\ldots,m = 2n_x$)
\begin{equation}
X_{i,k \mid k-1}^* = f(X_{i,k-1 \mid k-1},u_{k-1})
\end{equation}
\State Estimate the predicted state
\begin{algsubstates}
\State First
\State Second
\State Third
\State Last
\end{algsubstates}
\State Estimate the predicted error covariance
\begin{equation}
P_{k \mid k-1} = \frac{1}{m}\sum_{i=1}^m X_{i,k \mid k-1}^* X_{i,k \mid k-1}^{*T}
- \hat{x}_{k \mid k-1}\hat{x}_{k \mid k-1}^T + Q_{k-1}
\end{equation}
\end{algorithmic}
\end{algorithm}
\end{document}
上述代码不允许在 内引用algsubstates
。但是,以下内容应该可以:
\newcounter{algsubstate}
\makeatletter
\renewcommand{\thealgsubstate}{\arabic{ALG@line}.\alph{algsubstate}}
\makeatother
\newenvironment{algsubstates}
{\setcounter{algsubstate}{0}%
\renewcommand{\State}{%
\refstepcounter{algsubstate}%
\Statex {\footnotesize\alph{algsubstate}:}\space}}
{}
\ref
经验将是这种形式<state>.<substate>
(但可以改变)。