| 1 |
\section{Graphing functions} |
| 2 |
\label{sec:graphing} |
| 3 |
|
| 4 |
Among the most common types of figures for \TeX{} users are those which |
| 5 |
are the graphs of functions of a single variable. Hobby recognized this |
| 6 |
and constructed a package to accomplish this task. It is invoked by |
| 7 |
|
| 8 |
\begin{lstlisting}[style=MP] |
| 9 |
input graph; |
| 10 |
\end{lstlisting} |
| 11 |
|
| 12 |
\MP{} has the ability to construct data (i.e., ordered pairs) for |
| 13 |
graphing simple functions. However, for more complicated functions, the |
| 14 |
data should probably be constructed using external programs such as |
| 15 |
\acro{MATLAB} (or Octave), Maple, Mathematica, Gnuplot, et. al. |
| 16 |
|
| 17 |
A typical data file, say \File{data.d}, to be used with the \File{graph} |
| 18 |
package may have contents |
| 19 |
|
| 20 |
\vspace{8pt} |
| 21 |
\noindent% |
| 22 |
\begin{tabular}[b]{@{\hspace{48pt}}l@{}} |
| 23 |
\lstinputlisting[style=text, boxpos=b]{data.d} |
| 24 |
\end{tabular}% |
| 25 |
\qquad% |
| 26 |
\attach[subject={Graph data}]{data.d} |
| 27 |
\vspace{8pt} |
| 28 |
|
| 29 |
This data represents the graph of $f(x)=\sqrt{x}$ for six equally spaced |
| 30 |
points in $[0,1]$. To graph this data, the size of the graph must first |
| 31 |
be decided. Choosing a width of $144\mathrm{\ bp}$ and a height of |
| 32 |
$89\mathrm{\ bp}$, a minimally controlled plot (as in |
| 33 |
\autoref{fig:data}) of this data can be generated by |
| 34 |
|
| 35 |
\begin{lstlisting}[style=MP] |
| 36 |
draw begingraph(144bp,89bp); |
| 37 |
gdraw "data.d"; |
| 38 |
endgraph; |
| 39 |
\end{lstlisting} |
| 40 |
|
| 41 |
The \File{graph} package provides many commands used to customize |
| 42 |
generated graphs, and these commands are fully documented in the |
| 43 |
manual~\cite{hobby:graph} for the \File{graph} package. |
| 44 |
|
| 45 |
\begin{figure} |
| 46 |
\begin{withattachment}{data.mp} |
| 47 |
\centering |
| 48 |
\includegraphics{data.mps} |
| 49 |
\end{withattachment} |
| 50 |
\caption{$f(x)=\sqrt{x}$ using the \texttt{graph} package} |
| 51 |
\label{fig:data} |
| 52 |
\end{figure} |