Created
October 25, 2010 10:17
-
-
Save astanin/644724 to your computer and use it in GitHub Desktop.
An example of literate programming (LP) with Octave and Noweb
This file contains hidden or 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
| \section{Programming in Octave} | |
| Just like any other programming language, Octave has its loop and conditional | |
| constructs. The following example demonstrates how to generate the first 10 | |
| values of Fibonacci's sequence using a for loop: | |
| <<Fibonacci sequence>>= | |
| fib = [ 0, 1 ]; | |
| for i = 3:10 | |
| fib = [ fib, fib( i-2 ) + fib( i-1 ) ]; | |
| endfor | |
| fib | |
| @ | |
| \section{Source code} | |
| This document was produced with \verb!noweb! from the single \LaTeX/Octave | |
| source \verb!octavelp.nw!. See \verb!http://gist.github.com/644724!. | |
| We can process this source with \verb!noweave! to produce the documentation: | |
| \begin{quote}\begin{verbatim} | |
| $ noweave octavelp.nw > octavelp.tex | |
| $ pdflatex octavelp.tex | |
| \end{verbatim}\end{quote} | |
| To extract the source code, we use \verb!notangle!: | |
| \begin{quote}\begin{verbatim} | |
| $ notangle -RFibonacci\ sequence octavelp.nw > fibs.m | |
| $ octave -q fibs.m | |
| fib = | |
| 0 1 1 2 3 5 8 13 21 34 | |
| \end{verbatim}\end{quote} |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
After running
notangle -RFibonacci\ sequence octavelp.nw > fibs.m, the contents offibs.mis:Formatted documentation looks like this: octavelp.pdf.