美文网首页
Latex写算法伪代码

Latex写算法伪代码

作者: Eden0503 | 来源:发表于2020-02-24 00:56 被阅读0次

科研过程中利用Latex写文章是非常方便的一件事,下面是latex的一些写伪代码的代码。

1. Code One

\documentclass[conference]{IEEEtran}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{amsmath}
\begin{document}
%% 写算法伪代码或者流程的前期准备
\renewcommand{\algorithmicrequire}{\textbf{Input:}}  % Use Input in the format of Algorithm
\renewcommand{\algorithmicensure}{\textbf{Output:}} % Use Output in the format of Algorithm

\begin{algorithm}[h]
  \caption{Conjugate Gradient Algorithm with Dynamic Step-Size Control} % 名称
  \label{alg::conjugateGradient}
  \begin{algorithmic}[1]
    \Require
      $x_0$: initial individual, i.e, state;
      $x_0$: initial solution;
      $s$: step size;
    \Ensure
      optimal $x^{*}$
    \State initial $g_0=0$ and $d_0=0$;
    \Repeat
      \State compute gradient directions $g_k=\bigtriangledown f(x_k)$;
      \State compute Polak-Ribiere parameter $\beta_k=\frac{g_k^{T}(g_k-g_{k-1})}{\parallel g_{k-1} \parallel^{2}}$;
      \State compute the conjugate directions $d_k=-g_k+\beta_k d_{k-1}$;
      \State compute the step size $\alpha_k=s/\parallel d_k \parallel_{2}$;
    \Until{($f(x_k)>f(x_{k-1})$)}
  \end{algorithmic}
\end{algorithm}
\end{document}

Result One

result One.png

2. Code Two

\documentclass[conference]{IEEEtran}
\usepackage{algorithm}
\usepackage{algorithm}
\usepackage{algorithmicx}
\usepackage{algpseudocode}
\usepackage{amsmath}
\usepackage[top=2cm, bottom=2cm, left=2cm, right=2cm]{geometry}
\begin{document}

%% 写算法伪代码或者流程的前期准备
\renewcommand{\algorithmicrequire}{\textbf{Input:}}  % Use Input in the format of Algorithm
\renewcommand{\algorithmicensure}{\textbf{Output:}} % Use Output in the format of Algorithm

\begin{algorithm}[h]
  \caption{Pseudocode of Simulated Annealing Algorithm} % 名称
  \begin{algorithmic}[1]
    \Require
      $x_0$: initial individual or state;
      $T_0$: a high enough initial temperature;
      $T_{min}$: the lowest limit of temperature;
    \Ensure
       optimal state or approximate optimal state;
       \State set $x_0 = x_{best}$, compute initial energy function $E(x_0)$;
       \While {$T > T_{min}$}
         \For{$i = 1$; $i<n$; $i++$ }
      \State perturb current state $x_i$ for a new state $x_{new}$ and compute energy function $E(x_{new})$;
      \State compute $\Delta$ = $E(x_{new}-E(x_{(i)})$;
      \If {$\Delta$$E<0$} \State $x_{best} = x_{new}$
      \Else \State the probability $P = exp(-dE/T_{(i)})$;
      \If {$rand(0,1) < P$ }\State $x_{best} = x_{new}$
      \Else \State $x_{best} = x_{best}$
      \EndIf
     \EndIf
     \EndFor
      \State $T = T * $ $ \alpha$, where $\alpha$ is decay factor  ;
    \EndWhile
  \end{algorithmic}
\end{algorithm}

\end{document}

Result Two

Result Two.png

相关文章

  • Latex写算法伪代码

    科研过程中利用Latex写文章是非常方便的一件事,下面是latex的一些写伪代码的代码。 1. Code One...

  • 2018-04-03

    【LaTeX】Lyx/LaTeX笔记01---插入伪代码[latex]使用algorithm包来编写伪代码 - C...

  • Latex 写伪代码

    参考http://hustsxh.is-programmer.com/posts/38801.html[http:...

  • LaTeX输入伪代码

    第一种方式: 效果如下图: 第二种方式: 效果如下图: 第三种方式: 效果如下图: 如果使用beamer的话,就会...

  • 了解伪代码

    什么是伪代码? 伪代码(Pseudocode)是一种算法描述语言。使用伪代码的目的是使被描述的算法可以容易地以任何...

  • SMO算法实现

    这里根据SMO算法原论文中的伪代码实现了SMO算法。算法和数据已经上传到了git。 伪代码 python实现 分类...

  • ios常用算法大全

    ios常用算法大全 通用算法 (排序 查找 递归 链表等)欢迎大家来维护算法大全,有什么好的算法写的伪代码能运行测...

  • 最小生成树

    Kruskal算法 伪代码: 并查集:

  • 算法导论第2.1章 - 算法基础 (伪代码和循环不变式)

    伪代码 什么是伪代码?本书用伪代码来书写程序,使用清晰简洁的方式来说明给定的算法。类似我们常用的程序语言。伪代码的...

  • 伪代码书写

    伪代码是一种算法描述语言,使用伪代码的目的是为了使被描述的算法可以容易的以任何一种编程语言实现。因此伪代码必须结构...

网友评论

      本文标题:Latex写算法伪代码

      本文链接:https://www.haomeiwen.com/subject/vxhawqtx.html