LaTeX 写算法伪码


本系列文章由 @YhL_Leo 出品,转载请注明出处。
文章链接: http://blog.csdn.net/yhl_leo/article/details/50054953


LaTeX写算法伪码,需要包含包:

\usepackage{algorithm}
\usepackage{algpseudocode}

有些用例里还会加上:

\usepackage{caption}
\usepackage{algorithmicx}

可以遇到具体情形,再添加~


以常用的Levenberg-Marquardt(L-M)优化方法为例,给出一种方法:

\documentclass{article}
\usepackage{algorithm}
\usepackage{algpseudocode}
%\usepackage{caption}
%\usepackage{algorithmicx}

\begin{document}    

    \begin{algorithm}
		\caption{\textbf{Levenberg-Marquardt Method}}
		\label{Alg:scanMatching}
		\begin{algorithmic}[1]
			\Require 
			$k:= 0$ ; $\nu:=2$; $\mathbf{x}:=\mathbf{x}_0 $;
			$\mathbf{A}:= \mathbf{J}(\mathbf{x})^T\mathbf{J}(\mathbf{x})$;
			$\mathbf{g}:=\mathbf{J}(\mathbf{x})^T\mathbf{f}(\mathbf{x})$
			\Ensure $found := (\| \mathbf{g}\|_\infty \leq \varepsilon_1)$; $\mu := \tau\cdot max\{ a_{ii} \}$ 
			\State \textbf{while} (\textbf{not} $found $) $\textbf{and}$ $k \leq k_{max}$ $\textbf{do}$ 
			\State \ \ \ \ $k := k+1$; Solve $(\mathbf{A}+\mu\mathbf{I})\mathbf{h}_{lm}) = -\mathbf{g}$
			\State \ \ \ \ $\textbf{if} \ \ \|\mathbf{h}_{lm} \| \leq \varepsilon_2 (\|\mathbf{x} + \varepsilon_2)$
			\State \ \ \ \ \ \ \ \  $found:= \textbf{true}$
			\State \ \ \ \ $\textbf{else}$
			\State \ \ \ \ \ \ \ \ $\mathbf{x}_{new} := \mathbf{x} + \mathbf{h}_{lm}$
			\State \ \ \ \ \ \ \ \ $\varrho:= (F(\mathbf{x}) - F(\mathbf{x}_{new}))/(L(\mathbf{0}) - L(\mathbf{h}_{lm}))$
			\State \ \ \ \ \ \ \ \ $\textbf{if} \ \  \varrho > 0$
			\State \ \ \ \ \ \ \ \ \ \ \ \ $\mathbf{x}:= \mathbf{x}_{new}$
			\State \ \ \ \ \ \ \ \ \ \ \ \ $\mathbf{A} := \mathbf{J}(\mathbf{x})^T\mathbf{J}(\mathbf{x}); \ \ \mathbf{g}:=\mathbf{J}(\mathbf{x})^T\mathbf{f}(\mathbf{x})$
			\State \ \ \ \ \ \ \ \ \ \ \ \ $found := (\|\mathbf{g}\|_{\infty} \leq \varepsilon_1)$
			\State \ \ \ \ \ \ \ \ \ \ \ \ $\mu := \mu \cdot max\{ \frac{1}{3}, 1-(2\varrho-1)^3\}; \ \ \nu:=2$
			\State \ \ \ \ \ \ \ \ $\textbf{else}$
			\State \ \ \ \ \ \ \ \ \ \ \ \ $\mu := \mu \cdot \nu; \ \ \nu := 2\nu$
			\State \ \ \ \ \ \ \ \ $\textbf{end if}$
			\State \ \ \ \ $\textbf{end if}$
			\State \textbf{end while} 
		\end{algorithmic}
	\end{algorithm}

\end{document}

编译结果为:

LM

转载于:https://www.cnblogs.com/hehehaha/p/6332215.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值