forked from bueler/bueler.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompareMOP.tex
More file actions
86 lines (56 loc) · 4.13 KB
/
compareMOP.tex
File metadata and controls
86 lines (56 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
\documentclass[11pt]{amsart}
\usepackage[margin=1in, head=1in]{geometry}
\usepackage{fancyvrb,xspace}
\usepackage[pdftex,colorlinks=true,urlcolor=blue]{hyperref}
\parindent=0in
\parskip=0.5\baselineskip
%\fvset{fontsize=\small, numbers=left}
\DefineShortVerb{\|}
\newcommand{\mfile}[1]{
\begin{quote}
\VerbatimInput[frame=single,framesep=3mm,label=\fbox{\normalsize \textsl{\,#1\,}},fontfamily=courier,fontsize=\scriptsize]{#1}
\end{quote}
}
\newcommand{\Matlab}{\textsc{Matlab}\xspace}
\newcommand{\Octave}{\textsc{Octave}\xspace}
\newcommand{\python}{\textsc{Python}\xspace}
\newcommand{\ipython}{\textsc{ipython}\xspace}
\newcommand{\pylab}{\textsc{pylab}\xspace}
\newcommand{\scipy}{\textsc{scipy}\xspace}
\newcommand{\matplotlib}{\textsc{matplotlib}\xspace}
\begin{document}
\title{Comparison of \textsc{Matlab}, \textsc{Octave}, and \textsc{pylab}}
\author{Ed Bueler}
\date{\today.}
\maketitle
\normalsize
\thispagestyle{empty}
\newcommand{\hrf}[2]{\href{#1}{\texttt{#2}}}
On the next page are two algorithms each in \Matlab/\Octave form (left column) and \pylab form (right column). To download these examples, go to my page \hrf{http://bueler.github.io}{bueler.github.io}. To get \texttt{gaussint.m} below, for example, go to \hrf{http://bueler.github.io/gaussint.m}{bueler.github.io/gaussint.m}.
A bit of background is useful. \Matlab (\hrf{http://www.mathworks.com/}{www.mathworks.com}) was designed by Cleve Moler around 1980 for teaching numerical linear algebra without needing FORTRAN. It has since become a powerful programming language and engineering tool. More than half of UAF 600-level math/science/engineering students are already familiar with it. It is available in most labs and graduate student offices at UAF.
But I like free, open source software. There are several free alternatives to \Matlab, and two of these work well for this course. First, \Octave is a \Matlab clone. The ``\texttt{.m}'' examples on the next page work in an identical way in \Matlab and in \Octave. I will mostly use \Octave myself for teaching, but I'll test examples in both \Octave and \Matlab. To download \Octave, go to
\hrf{http://www.gnu.org/software/octave/}{www.gnu.org/software/octave}.
Second, the \scipy (\hrf{http://www.scipy.org/}{www.scipy.org}) and \matplotlib (\hrf{http://matplotlib.org/}{matplotlib.org}) libraries give the general-purpose interpreted language \python (\hrf{http://python.org/}{python.org}) all of \Matlab functionality plus quite a bit more. This combination is called \pylab. Using it with the \textsc{ipython} interactive shell (\hrf{http://ipython.org/}{ipython.org}) gives the most \Matlab-like experience. The examples on the next page hint at the computer language differences and the different modes of thought between \Matlab/\Octave and \python. Students who already use \python will like this option.
Here are some brief ``how-to'' comments for the \Matlab/\Octave examples: \texttt{gaussint.m} is a \emph{script}. A script is run by starting \Matlab/\Octave, usually in the directory containing the script you want to run. Then type the name of the script at the prompt, without the ``.m'':
\verb|>> gaussint|
\noindent Typing
\verb|>> help gaussint|
\noindent shows the block of comments as documentation.
\noindent The second algorithm \verb|bis.m| is a \emph{function} which needs inputs. At the prompt enter
\begin{Verbatim}
>> f = @(x) cos(x) - x
>> bis(0,1,f)
\end{Verbatim}
for example. We have given \verb|bis.m| three arguments; the last is an ``anonymous function.''
For the \python versions: Type \verb|run gaussint.py| at the \ipython prompt or \verb|python gaussint.py| at a shell prompt. For the function \verb|bis.py|, run \python or \ipython and do: \verb|from bis import bis|. In \ipython you can type \verb|bis?| to get documentation for that function, and run the example as shown in the docstring.
\vfill
\newpage
\vfill
\begin{tabular}{ll}
\hspace{-0.45in}\parbox{3.6in}{\mfile{gaussint.m}} & \hspace{-0.4in}\parbox{3.8in}{\mfile{gaussint.py}}
\end{tabular}
\begin{tabular}{ll}
\hspace{-0.45in}\parbox{3.6in}{\mfile{bis.m}} & \hspace{-0.4in}\parbox{3.8in}{\mfile{bis.py}}
\end{tabular}
\vfill
\end{document}