我的代码如下,我没有发现错误。
\begin{algorithm}[H]
\SetAlgoLined
\textbf{Input} :$x_{k-1}$,$P_{k-1}$,$u_{k}$,$z_{k}$\;
\textbf{Output} : $x_{k}^{-}$,$P_{k}^{-}$ \\~\\
$x_{k+1}={\Phi{x}}_{k-1}+{Bu}_{k}+{G\omega}_{k}$
$P_{k}={\Phi{P}}_{k-1}{\Phi}^{T}+Q$
$K=PH^{T}(HPH^{T}+R)^{-1})$
$z=(z_{k}-H_{k}x_{k})$
$x_{k}^{-}=x_{k}+kz$
$P_{k}^{-}=P-KHP$
\textbf{return}$ x_{k}^{-}$,$P_{k}^{-}$
\caption{ \textsc{Kalman Filter} }
\end{algorithm}
答案1
您需要使用\;
来关闭每个语句,否则内容将被视为同一行的一部分:
\documentclass{article}
\usepackage{algorithm2e}
\SetKwInOut{Input}{Input}
\SetKwInOut{Output}{Output\,}
\SetAlgoLined
\DontPrintSemicolon
\begin{document}
\begin{algorithm}[H]
\Input{$x_{k - 1}$, $P_{k - 1}$, $u_k$, $z_k$}
\Output{$x_{k}^{-}$, $P_k^{-}$}
\BlankLine
$x_{k + 1} = \Phi(x)_{k - 1} + Bu_k + G\omega_k$\;
$P_k = \Phi(P)_{k - 1} \Phi^T + Q$\;
$K = PH^T (HPH^T + R)^{-1})$\;
$z = (z_k - H_k x_k)$\;
$x_k^{-} = x_k + k z$\;
$P_k^{-} = P - KHP$\;
\textbf{return} $x_k^{-}$, $P_k^{-}$\;
\caption{\textsc{Kalman Filter}}
\end{algorithm}
\end{document}