zoukankan      html  css  js  c++  java
  • 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}
    
    egin{document}    
    
        egin{algorithm}
    		caption{	extbf{Levenberg-Marquardt Method}}
    		label{Alg:scanMatching}
    		egin{algorithmic}[1]
    			Require 
    			$k:= 0$ ; $
    u:=2$; $mathbf{x}:=mathbf{x}_0 $;
    			$mathbf{A}:= mathbf{J}(mathbf{x})^Tmathbf{J}(mathbf{x})$;
    			$mathbf{g}:=mathbf{J}(mathbf{x})^Tmathbf{f}(mathbf{x})$
    			Ensure $found := (| mathbf{g}|_infty leq varepsilon_1)$; $mu := 	aucdot max{ a_{ii} }$ 
    			State 	extbf{while} (	extbf{not} $found $) $	extbf{and}$ $k leq k_{max}$ $	extbf{do}$ 
    			State     $k := k+1$; Solve $(mathbf{A}+mumathbf{I})mathbf{h}_{lm}) = -mathbf{g}$
    			State     $	extbf{if}   |mathbf{h}_{lm} | leq varepsilon_2 (|mathbf{x} + varepsilon_2)$
    			State          $found:= 	extbf{true}$
    			State     $	extbf{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         $	extbf{if}    varrho > 0$
    			State             $mathbf{x}:= mathbf{x}_{new}$
    			State             $mathbf{A} := mathbf{J}(mathbf{x})^Tmathbf{J}(mathbf{x});   mathbf{g}:=mathbf{J}(mathbf{x})^Tmathbf{f}(mathbf{x})$
    			State             $found := (|mathbf{g}|_{infty} leq varepsilon_1)$
    			State             $mu := mu cdot max{ frac{1}{3}, 1-(2varrho-1)^3};   
    u:=2$
    			State         $	extbf{else}$
    			State             $mu := mu cdot 
    u;   
    u := 2
    u$
    			State         $	extbf{end if}$
    			State     $	extbf{end if}$
    			State 	extbf{end while} 
    		end{algorithmic}
    	end{algorithm}
    
    end{document}

    编译结果为:

    LM

  • 相关阅读:
    Pandas缺失值处理
    文件读取与存储
    DataFrame运算
    C++11 不抛异常的new operator
    In p = new Fred(), does the Fred memory “leak” if the Fred constructor throws an exception?
    method chaining
    C++中的运算符重载
    Why am I getting an error converting a Foo** → const Foo**?
    The constness of a method should makes sense from outside the object
    Virtual Friend Function
  • 原文地址:https://www.cnblogs.com/hehehaha/p/6332215.html
Copyright © 2011-2022 走看看