MAS116/MAS117 PRESENTATION LAB 4
IMPORTANT! If you are asked to install packages when processing your file, click ‘yes’ then wait. You may need to do this for multiple packages. At points it may look as though nothing is happening but your PDF should appear eventually. Interrupting the process can cause problems, so make sure you wait long enough!
Open TeXworks or TeXmaker or whichever editor you prefer. Find the preamble template on the course webpage in the ‘Extras’ section, and copy and paste this to start this week’s document.
If your computer is unsure what to do with .tex files like the template on the course webpage, you can open it in any text editor (e.g. Notepad).
Let’s start by creating some graphs using pgfplots. You need to ensure that
\usepackage{pgfplots}
is in your preamble; you will need to delete the
comment symbol, %
from the template. Start a new section called ‘Graphs
created with PGFplots’ then enter the following.
\begin{tikzpicture} \begin{axis}[ title={$y=\sin x$}, xlabel=$x$, ylabel=$y$] \addplot[smooth, domain=-360:360]{sin(x)}; \end{axis} \end{tikzpicture}
If you get errors here, check that you have recreated the text precisely, including commas and the semicolon.
axis lines=center,
title={$y = \sin x$},
tikzpicture
environment inside a center
environment.
Note the US spelling of ‘center’.
-2*pi:2*pi
.
What’s happened now? PGFplots’s trigonometric functions work in
degrees: the deg(x) function takes a number (in radians) and turns it
into the value in degrees; that is, .Try a 3D plot, using the following code.
\begin{tikzpicture} \begin{axis}[xlabel=$x$, ylabel=$y$] \addplot3[domain=-1.5:1.5, surf]{-exp(-x^2 - y^2)}; \end{axis} \end{tikzpicture}
ylabel=$y$
do?
(Note the US spelling of the word “color”.)There are many more examples of graphs – with source code – on the PGFplots website, http://pgfplots.sourceforge.net/gallery.html. If you need to make a graph, a combination of the simple techniques on this sheet and what you find at the link above should do the trick.
Now let’s try including an image from external software. Open a new tab in your browser and go to https://www.geogebra.org/geometry. Geogebra is a point-and-click geometry package which can do more than just create pictures for including in documents.
Play around further if you like. Once you have a picture you are happy with, go
to the options in the top-left, click Download As, then choose PDF as the file
type and save the image as geogebra_image.pdf
in the same folder as your
LaTeX document.
Return to your LaTeX document. Put \usepackage{graphicx}
in your
preamble. Start a new section called ‘Including image files’ and put the command
\includegraphics{geogebra_image.pdf}
underneath. Your picture should
appear though it may not fit properly at this stage. Convince yourself the picture
stays smooth no matter how far you zoom in.
If you have problems, check that the name of the uploaded file is exactly the same in the includegraphics command as it is in the filename, and make sure the file is saved in the same folder as the .tex file.
\includegraphics
command by changing \includegraphics
to \includegraphics[scale=0.5]
. What has changed?
\includegraphics[width=8cm]
.
\includegraphics[width=\textwidth]
.
\includegraphics[width=0.8\textwidth]
.
center
environment.Note that this might have resulted in an image where the labels are unreadable! You should always ensure that labels are legible. In this case you would have to go to geogebra and either alter the font size or else the range of the image that is exported. If you have lots of time in the lab, you should try to see how you can alter the font size in geogebra.
To enable images to be referenced, they should be placed inside the figure
environment; this will allow you to refer to Figure 1, for instance. Try this
instead of using center
, so that your LaTeX reads
\begin{figure}[tbh] \includegraphics[width=0.8\textwidth]{geogebra_image.pdf} \caption{A Geogebra picture} \end{figure}
LaTeX will move figure environments around the document depending on the size of the figure and the space available. Environments like this are called ‘floats’ as they can float around the document. If you are looking this in a PDF document, you will see Figure 1 has ‘floated’ to the top of the page. You might find this behaviour annoying to start with, but it is the standard way to do things in professional documents.
The term [tbh]
after \begin{figure}
is telling LaTeX to put the figure at the
top of a page if there’s room, and if not try the the bottom of the page and then
here, i.e., at the position it appears in the LaTeX document. Don’t fight this! Let
LaTeX put floats where it thinks is sensible.
Now add \label{fig:geogebra}
after the \caption{...}
command, then write
the following sentence underneath the figure environment
Geogebra creates good diagrams; see Figure~\ref{fig:geogebra}.
Process your file to see the figure being referenced automatically.
The tilde, ~
, puts in a space, but does not allow it to be split across lines. You
should do this when using \ref
as “Figure 1” looks good but “Figure 1” does
not.
Create a document with title ‘MAS116: Homework 4’ (or MAS117) and your name on as author. Your task this week is to look up Lagrange Interpolation and to write a page or so of LaTeX explaining it. In particular, given points for , explain why the function defined below is a quadratic polynomial whose graph passes through the points , and :
You could look on the internet, or in search the University library’s digital collection. For instance, the theory is covered in the book by Stroud listed below which is available to view online there.
Note that you must write this in your own words, you must not copy directly from any other source.
Things that may help you with your write-up include the following.
Print out and hand in the PDF and LaTeX file of your homework at next week’s lab, as usual. Remember that this is assessed coursework so must be your own work; colluding with others is cheating and may make you subject to disciplinary proceedings.