算法的编号步骤

算法的编号步骤

假设我需要在算法中编号步骤内添加步骤,并且希望它们用字母自动标记。

我尝试使用\begin{description} \end{description},但在某些时候我需要划分我的算法(长算法),并且当我想划分算法时使用描述环境会导致问题,有人可以帮忙吗?

\documentclass[a4paper,english,12pt,oneside]{book}
%\documentclass[11pt,draft]{article}
%\usepackage{fullpage}
%\usepackage[top=1in, bottom=1in, left=1in, %right=1in]{geometry}
%\usepackage[margin=1in, paperwidth=8.5in, paperheight=11in]{geometry}
\usepackage[left=2cm, right=2cm, top=2.5cm, bottom=2.5cm]{geometry}
%\usepackage[left=20mm]{geometry}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{graphicx}
\usepackage{refstyle}
\usepackage{subcaption}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{enumerate}
\usepackage{epstopdf}
\usepackage{breqn}
\usepackage{mathtools}
%--------------------------------------------------------------------------------------------------
%\usepackage{a4wide}
\usepackage{amsfonts}
\usepackage{amstext}
\usepackage{amsthm}
\usepackage{newlfont}
\usepackage{graphics}
\usepackage{tabularx}
\usepackage{geometry}
\usepackage{lscape}
\usepackage{multirow}
\usepackage{epsfig}
%----------------------------------------------------------------------------------------------------
\usepackage{algorithm}
\usepackage{algcompatible}
\usepackage{algorithmicx}
\usepackage{algpseudocode}
\usepackage{pifont}
%\usepackage[lite]{mtpro2}
%----------------------------------------------------------------------------------------------------
%------------------------------------------------------------------------------------------------------------------------------
\usepackage{color}
\definecolor{violet}{rgb}{0.7,0.2,0.8}
\definecolor{bluevert}{rgb}{0,0.9,1}
\definecolor{trustcolor}{rgb}{0.71,0.14,0.07}
\definecolor{PinkTriton}{rgb}{.708 ,.055 ,.275}
\definecolor{RedTriton}{rgb}{.491 ,.097 ,.066} % couleur rouge du triton
\definecolor{OrangeTriton}{rgb}{.953 ,.502 ,.04}
%------------------------------------------------------------------------------------------------------------------------------
\usepackage[colorlinks=true,linkcolor=blue, citecolor=blue]{hyperref}

% define new commandes-------------------------------------------------------------------
\def\blank{\medskip\hrule\medskip}

%-----------------------------------------------------------------------------------------
\begin{document}
%\algstore{myalg}
 %   \end{algorithmic}
 %   \end{algorithm}
 %   \begin{algorithm}                     
 %   \begin{algorithmic} [1]              
 %   \algrestore{myalg}
%-------------------------------------------------------------------------------------------------------
\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
    \label{eq:Ref_3}
    \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
    \label{eq:Ref_3}
    \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})
    \label{eq:Ref_3}
    \end{equation} 
  \State Estimate the predicted state
    \begin{equation}
    \hat{x}_{k|k-1} = \frac{1}{m}\sum_{i=1}^m{X_{i,k|k-1}^*}Y
    \label{eq:Ref_3}
    \end{equation}
  \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} 
    \label{eq:Ref_3}
    \end{equation} 
\end{algorithmic}

 \textbf{Measurement update}\\

\begin{algorithmic}[1]          
  \State Factorize the state error covariance matrix:
    \begin{equation}
    P_{k|k-1} = S_{k|k-1}S_{k|k-1}^T
    \label{eq:Ref_3}
    \end{equation}
  \State Evaluate the cubature point (i=1,2,...,m)
    \begin{equation}
    X_{i,k|k-1} = \hat{x}_{k|k-1} + S_{k|k-1}\zeta_i
    \label{eq:Ref_3}
    \end{equation}
  \State Evaluate the propagated cubature point through the measurement equation
    \begin{equation}
    Y_{i,k|k-1} = h(X_{i,k|k-1})
    \label{eq:Ref_3}
    \end{equation}
    \begin{description}
  \item[a.] Estimate the predicted measurement
    \begin{equation}
    \hat{y}_{k|k-1} = \frac{1}{m}\sum_{i=1}^m{Y_{i,k|k-1}}
    \label{eq:Ref_3}
    \end{equation}
  \item[b.] Estimate the innovation covariance matrix 
    \begin{equation}
    P_{yy,k|k-1} = \frac{1}{m}\sum_{i=1}^m{Y_{i,k|k-1}Y_{i,k|k-1}^T}-\hat{y}_{k|k-1}\hat{y}_{k|k-1}^T+R_k
    \label{eq:Ref_3}
    \end{equation}  
  \item[c.] Estimate the cross-covariance matrix
    \begin{equation}
P_{xy,k|k-1}=\frac{1}{m}\sum_{i=1}^m{X_{i,k|k-1}Y_{i,k|k-1}^T}-\hat{x}_{k|k-1}\hat{y}_{k|k-1}^T
    \label{eq:Ref_3}
    \end{equation}
% split long alg-----------------------------------------------------------------------------------
      \algstore{myalg}
  \end{algorithmic}
\end{algorithm}

\clearpage

\begin{algorithm}
  \ContinuedFloat
%  \caption{Square Root Cubature Kalman Filter SRCKF (continued)}
  \begin{algorithmic}
      \algrestore{myalg}
%--------------------------------------------------------------------------------------------------    
  \item[d.] Estimate the Kalman gain
    \begin{equation}
    K_k=P_{xy,k|k-1}(P_{yy,k|k-1})^{-1}
    \label{eq:Ref_4}
    \end{equation}
    \end{description}
  \State Estimate the Updated state
    \begin{equation}
    \hat{x}_{k|k}=\hat{x}_{k|k-1}+K_k(y_k-\hat{y}_{k|k-1})
    \label{eq:Ref_2}
    \end{equation}
  \State Estimate the corresponding error covariance
    \begin{equation}
    P_{k|k}=P_{k|k-1}-K_kP_{yy,k|k-1}K^T_k
    \label{eq:Ref_3}
    \end{equation} 
\end{algorithmic}
\end{algorithm}

\end{document}

相关内容