有關此演算法的任何幫助

有關此演算法的任何幫助

我正在嘗試用 LaTeX 編寫一個演算法。例如,我使用此模板,並且我需要此步驟的幫助

第一個循環mik=aik/akk;

和第二個循環aij=aij-mikakj;

最後完成最後一個循環

bi=bi=mikbk;

如何在 LaTeX 程式碼中編寫這個?

\section{The algorithm which solves the method Gaussian elimination}
\For{$k$=1$:$1$n-1$}{
    \For{$i=k+1:1:n$}\;
       {write the first loop here}{
      \For{}
      {write the second loop here}
        instructions1\; finish here
        instructions2\;
      {final loop there}
    }{
        instructions3\;
    }
}
\caption{How to write algorithms}

抱歉這個錯誤,請幫忙解決這個問題。

答案1

以下內容可作為起點:

\documentclass{article}
\usepackage[ruled]{algorithm2e}

\begin{document}
\begin{algorithm}[H]
    \caption{Test algorithm}
    \SetAlgoLined
    \For{contition}{
        \For{some text here}{
            some text\\
            \For{other stuff}{
                whatever comes here
            }
         some more text
         }
    }

\end{algorithm}
\end{document}

答案2

\begin{algorithm}[H]
\caption{Test algorithm}
\SetAlgoLined
\For{$k=1:1:n-1$}{
    \For{$i=k+1:1:n$}{
          $m_{i}{k}=a_{i}{k}/a_{k}{k}$\\
        \For{other stuff}{
            $a_{i}{j}=a_{i}{j}-m_{i}{k}a_{k}{j};$\\
        }
        $b_{i}=b_{i}-m_{i}{k}b_{k};$
    }
}\end{algorithm}

是正確的

相關內容