Last active
August 29, 2015 13:56
-
-
Save shane5ul/9198418 to your computer and use it in GitHub Desktop.
Minimal Example of LaTeX file using lstlistings to produce formatted Octave code with highlighting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\documentclass[xcolor=dvipsnames]{beamer} | |
\usepackage{graphics, listings} | |
\definecolor{gray}{rgb}{0.85,0.85,0.85} | |
\lstset{frame=single, | |
basicstyle=\tiny,backgroundcolor=\color{gray}, | |
language=Octave, | |
keywordstyle=\color{blue}, | |
stringstyle=\color{BrickRed}, | |
commentstyle=\color{OliveGreen}} | |
\begin{document} | |
\begin{frame}[fragile] | |
\frametitle{Algorithm for Determining Maxima} | |
\begin{lstlisting} | |
function xopt = golden(xl, xu, tol) | |
R = (sqrt(5) - 1)/2 % golden ratio | |
d = R * (xu - xl) | |
x1 = xl + d; f1 = f(x1) | |
x2 = xu - d; f2 = f(x2) | |
while (xu - xl > tol) | |
d = R * d % interval shrinks by factor R | |
if (f1 > f2) | |
xl = x2 | |
x2 = x1 | |
x1 = xl + d | |
f2 = f1 | |
f1 = f(x1) | |
else | |
xu = x1 | |
x1 = x2 | |
x2 = xu - d | |
f1 = f2 | |
f2 = f(x2) | |
endif | |
endwhile | |
xopt = (xu + xl)/2 | |
endfunction | |
\end{lstlisting} | |
\end{frame} | |
\end{document} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment