-
Notifications
You must be signed in to change notification settings - Fork 1
/
02_Graphing.tex
190 lines (134 loc) · 12.5 KB
/
02_Graphing.tex
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
\chapter{Graphing}
\section{Objectives}
\begin{enumerate}
\item To learn to plot graphs using (i) a pencil and graph paper, (ii) spreadsheets, and (iii) Python.
\end{enumerate}
\section{Introduction}
Before you begin, read the \href{https://www.physics.mun.ca/~cdeacon/publications/graphs_tpt.pdf}{article on graphing by Christopher Deacon}. You don't need to grasp all the points in it right way, but as you grow in experience you will appreciate them.
While we will show you how to use Python, the purpose of this lab is not to familiarise you to coding -- there is another course that does that. Everything here can alternatively be done using MS Excel.
\begin{imp}
As with the other Physics courses, we will be using \textbf{\href{https://jupyter.org}{Jupyter Notebook}} for coding in Python. Go to the link and follow the instruction procedure to install \href{https://www.anaconda.com/downloads}{Anaconda}, a Python distribution that comes with Jupyter pre-installed. This installation takes a significant amount of time. As a result, you should get it done \textbf{before this session begins}.
\end{imp}
\section{Graphing using a pencil and graph paper}
Graphing, like many other scientific activities, begins with a set of questions: we wish to find something, in this case a pattern, and we would like to plot our graph in such as way as to see and show that pattern most effectively. Some of these patterns may already be obvious in the data, e.g. you must have noticed that the time period $T$ of the pendulum does not seem to depend on the mass $m$ of the bob. When you compare the columns for $T$ and the length $l$ of the pendulum, you see that $T$ increases with $l$, but not in the most obvious way. Finally, when you look at how (and whether) $T$ changes with the amplitude $\theta$ of the oscillation, you will see no obvious pattern, even though there is one hidden in the data.
\subsection{Plotting: Stage 1}
Let us begin by exploring the variation of $T$ with respect to $m$ and with respect to $l$. We will consider the variation of $T$ with $\theta_\text{o}$ later.
\vspace{-0.5cm}
\begin{enumerate}
\itemsep0em
\item On a graph sheet, draw the $x$ and $y$ axes. The $x$ axis is normally used for the parameter that you control, sometimes called the independent parameter, and $y$ axis for the parameter that you observe, sometimes called the dependent parameter. For example, when you plot $T$ vs $m$, $T$ is along $y$ and $m$ along $x$.
\item Along each axis, choose a range that (i) covers the values you use and observe, and (ii) uses a scale that assigns a reasonable value to each division of the grid. So far as possible use units that make the numbers for the variables (i) small and (ii) similar along both axes. (If you write the mass in $kg$ and the time in $s$, you will understand what \textit{not} to do.)
\item Plot the observed point, and then circle each point so that it visible.
\item If the pattern appears to be straight line, use a ruler to draw the line that seems intuitively the most appropriate. (We will see later what this means.) If the pattern seems non-linear, sketch free-hand the curve that seems, once again, most appropriate.
\end{enumerate}
\subsection{Plotting: Stage 2}
You will have noticed that the way $T$ changes with $l$ is not linear. In fact, if you look carefully at the values, you will see that when $l$ is doubled, $T$ changes by about a factor of $1.4$. Since $1.4$ is close to $\sqrt{2}$, this suggests that it is $T^2$ that doubles when $l$ is doubled. In other words, we expect a linear dependence of $T^2$ on $l$. To see if this true, plot $T^2$ against $l$.
\subsection{Plotting: Stage 3}
If $T^2$ depends linearly on $l$, $T$ must depend linearly on $\sqrt{l}$. This implies that $\log T$ depends linearly on $\log l$. Make columns for $\log T$ and $\log l$ in your table, and make the corresponding plot.
\begin{question}
\paragraph{Question:} Compare the slopes of the $T^2 - l$ and $\log T - \log l$ graphs.
\paragraph{Question:} What are the advantages of plotting the log of a quantity?
\paragraph{Question:} Suppose that you are examining the variation of $y$ with respect to $x$, it is sometimes useful to plot $\log y$ vs $x$ (not $\log x$). What kind of dependence would this indicate?
\end{question}
\section{Graphing using your computer}
When you were drawing the $T^2 - l$ and $\log T - \log l$ graphs you were essentially using your artistic sense, which allowed you to judge what the \textit{best} straight line is, i.e. the line that seems to best fit the points. Notice that the confidence with which you arrive, artistically, at the the best line depends on the scatter of the points about it. Thus, the greater the scatter, the less confident you are (or ought to be) of your artistic fit. It becomes imperative, therefore, to find an unambiguous, quantitative way of arriving at the best fit.
To do this we begin by understanding that a straight line is determined \textit{completely} by just two points. In other words, when we have more than two points, there is no such thing as \textit{the} line that fits the points. In mathematical language, the problem is \textit{over-determined}. However, we can certainly ask what is the \textit{best} line, i.e. the one that is most representative of all the points, or, in some sense (yet to be defined) closest to them.
To find the best line, we go back to the remark that a line is determined completely by two points. Another way of saying this is that a line is determined uniquely by two \textit{parameters} -- the slope $m$ and the $y$-intercept $c$. So when we have many points, we can think of a host of lines with different with a range of different $m$s and $c$s. The question is: Which line is the best? To answer this question mathematically (rather than artistically) we need a quantitative measure of the \textbf{goodness of fit} of a line given more than two points. This measure of the goodness of fit must depend on $m$ and $c$, and the process of finding the best line is thus the process of \textit{optimisation} with respect to $m$ and $c$. The mathematics of this is a little advanced, but by the end of this semester you will be able to work it out.
For the moment, you will allow the computer to use standard algorithms to find the best straight line for us. To do that, you have to learn how to get our computer to import the data we want to plot and use it in such a way as to find the best straight line. For that purpose we will first use Microsoft Excel and then Python.
\begin{question}
\paragraph{Question:} Show that if you have just two points, then $m$ and $c$ are uniquely determined.
\end{question}
\subsection{Graphing with Microsoft Excel}
Excel is a \textit{spreadsheet}. Computer spreadsheets are powerful tools to analyse data and are used in a variety of different disciplines as they allow one to represent and analyse data easily and efficiently.
\begin{tip}
We will be describing using Microsoft Excel in this section. However other spreadsheet programs are very similar. For example, LibreOffice Calc and Google Spreadsheets are two other programs that can be used and possess more or less the same functionality.
\end{tip}
\subsubsection{Tabulating Data}
Let's begin with a sample data table verifying Ohm's law, shown in Table (\ref{table:ohm}).
\begin{table}[!htb]
\centering
\begin{tabular}{|C{4cm}|C{4cm}|}
\hline
\rowcolor{orange!25}
\hline
\multicolumn{2}{|l|}{Experiment $n$: }\\
\rowcolor{orange!25}
\multicolumn{2}{|l|}{\textbf{Verification of Ohm's Law for a large resistance}}\\
\hline
\multicolumn{2}{|l|}{Data collected by: Philip Cherian,}\\
\multicolumn{2}{|l|}{Expt. performed : 29/01/2019 to 05/01/2019}\\
\hline
\multicolumn{2}{|l|}{Resistance $R1$; Multimeter \textit{Victor} VC97}\\
\hline
\rowcolor{orange!50}
\textbf{Voltage} {\color{black}(V)} & \textbf{Current} {\color{black}($\mu A$)}\\
\hline
1&3\\
2&5\\
3&6\\
4&7\\
5&10\\
6&13\\
7&15\\
8&16\\
9&19\\
10&20\\
11&22\\
12&24\\
13&26\\
14&29\\
15&31\\
16&33\\
17&35\\
18&36\\
19&39\\
20&41\\
\hline
\end{tabular}
\caption{Sample data for verification of Ohm’s law for a large resistance.}
\label{table:ohm}
\end{table}
Reproduce the above data table in MS Excel (be sure you learn how to include the $\mu$ symbol!\footnote{You will often need to insert Greek characters ($\lambda$, $\theta$, $\sigma\hdots$); add these using the \texttt{Insert} $\rightarrow$ \texttt{Symbol} option in MS Excel. Google Sheets does not have this functionality, but you can paste special characters from Google Docs.}).
\begin{tip}
Leave a few rows at the top of the spreadsheet for information about the data collected. In the above case we have included the information about who took the data and when, and also information about the equipment.
\end{tip}
\subsubsection{Plotting and Formatting your Graph}
You are now ready to begin plotting this data. Begin by selecting both columns and \texttt{Insert} a \texttt{Chart}. When you are asked to select a \texttt{Chart Type}, select the \texttt{XY (Scatter)} option with points \textbf{only}. This is important: you might be tempted to ``join the dots'', but that would be misleading: especially if the graph is not linear! When you are done with this, label your axes (\textbf{including units!}): most spreadsheet software take the first column to be the $x$-values and the second the $y$-values, but this can be changed. Your graph should look something like Figure (\ref{fig:samplegraph1}).
\begin{figure}[!htb]
\centering
\includegraphics[scale=0.75]{figs/samplegraph1.png}
\caption{Sample graph of the data in Table (\ref{table:sampledata}) with much to be improved.}
\label{fig:samplegraph1}
\end{figure}
Excel's biggest user base is business, so default graph formats are mostly setup for that purpose. As a result, changes need to be made to bring it to a ``scientific'' format: \begin{enumerate}
\item Remove any unnecessary white space. You can do this by adjusting the minimum and maximum values of the axes. Do this by right clicking the axes and selecting \texttt{Format Axes}.
\item Remove the legend on the right when possible: any information regarding the graph should be added in the caption. You can select it and press \texttt{Delete}.
\item Change the marking icon to a more scientific size and shape. You can right click the graph and select \texttt{Format Data Series} and edit the icon size and shape there.
\item Remove the grid-lines in the plot area.
\end{enumerate}
You should now have a graph like the one shown in Figure (\ref{fig:samplegraph2}).
\begin{figure}[!htb]
\centering
\includegraphics[scale=0.8]{figs/samplegraph2.png}
\caption{Same graph as in Figure (\ref{fig:samplegraph1}), with some modifications made.}
\label{fig:samplegraph2}
\end{figure}
\subsubsection{Adding a Trendline}
It should appear to you now that this trend is quite linear. We can now use the computer's algorithm to get the ``best'' straight line between these points. Don't worry right now about how this is done, you will learn about this in some detail at a later point.
Right-clicking the data-points, select \texttt{Add Trendline}. In the dialog box that opens, choose a \texttt{Linear} regression type and select the checkbox that says \texttt{Show Equation}. You can also make the line dotted, and change its colour.
If your trendline equation looks something like this:
\begin{center}
\texttt{f(x) = 2.02556390977444 x + 0.231578947368423}
\end{center}
then edit it to round it off to a more reasonable number of digits. You will understand how many digits is reasonable in the next chapter on error analysis, for right now, let us choose to keep three decimal places. You should now have a graph that looks like Figure (\ref{fig:samplegraph3}).
\begin{figure}[!htb]
\centering
\includegraphics[scale=0.8]{figs/samplegraph3.png}
\caption{Same graph as in Figure (\ref{fig:samplegraph1}), with a formatted trendline.}
\label{fig:samplegraph3}
\end{figure}
\begin{tip}
In Microsoft Excel, you can make the current graph style a ``template'', so that you don't have to keep making most of these changes every time you plot new data. To do this, right-click the chart, and select \texttt{Save as Template}. Choose an appropriate name for the chart template and save it. The chart template automatically appears in the \texttt{Templates} folder for charts. You can access it on the \texttt{All Charts} tab in the \texttt{Insert Chart} or \texttt{Change Chart Type} dialog box, where you can apply a chart template like any other chart type.
\end{tip}
%\todo[inline,color=cyan]{Include corrected JupterNotebooks.}
\newpage