\documentclass[fleqn,nopageno,letterpaper,11pt]{article}

\input{/Users/pleclair/Documents/Alabama/Teaching/PH101/defs}

\usepackage{garamond}

\headheight 0.25in
\headsep 3ex
\topmargin -0.25in
\textheight 8.75in
\textwidth 6.5in
\oddsidemargin 0in
\evensidemargin 0in

%\parindent 0in 
 
\begin{document} %\garamond
\pagestyle{fancy}

\lhead[\fancyplain{}{}]           {\fancyplain{}{{\sc \large Group Members}}}
\rhead[\fancyplain{}{}]           {\fancyplain{}{{\sc }}}

\begin{center} 
	{\sc \large  University of Alabama}\\
	{\large Department of Physics and Astronomy}\\ \bigskip
	{\large PH105 / LeClair  \hfill \today} \bigskip
	
{\bf \Large Laboratory 2: Falling objects} 
\end{center} 

{\em Hypothesis:} The motion of a falling object is characterized by a constant acceleration, a velocity which increases linearly in time, and a position which increases quadratically in time.

{\em Goals:}  Understanding of linear regression analysis (``trendlines'') and correlation; use of DataStudio software.

\section{Introduction}

At this point, you should be familiar with the basic equations of one dimensional motion without air resistance. In the present experiment, we will release an object from rest a distance $x_o$ from a motion sensor, and will track its position, velocity, and acceleration. The relevant equations we have developed are, presuming the motion to occur along the $x$ axis,

\begin{align}
x(t) &= x_o + v_ot + \frac{1}{2}at^2 = x_o \pm \frac{1}{2}gt^2\\
v(t) &= v_o + at = v_o \pm gt\\
a &= \pm g
\end{align}

\noindent Here $t$ is time, $x(t)$ is position as a function of time, $v(t)$ is velocity as a function of time, $v_o\!=\!0$ is the initial velocity (the object starts out at rest), $a$ is the acceleration, and $g\!\approx\!9.8\,\text{m/s}^2$ is the acceleration due to gravity. The $\pm$ sign indicates that the acceleration may be $+g$ or $-g$, depending on whether the object falls toward or away from the sensor; which is which is something you will need to figure out during the experiment!

It is the goal of this experiment to verify these relationships and learn a few data analysis techniques that we will use throughout the course.

\subsection{Linear regression and trendlines}

Let's say we have a series of data on an $x\!-\!y$ plot which seemed to be scattered about a straight line, i.e., the data seem to at least approximately obey a linear relationship. Better yet, perhaps we even have a theoretical model which {\em predicts} a linear relationship for this particular experimental data. This is the case for the $v(t)$ data you will generate during your experiment.\\

{\em Linear regression} attempts to model the relationship between two variables (say, $x$ and $y$) by fitting a linear equation (a line) to the observed data. One variable is considered to be an explanatory variable (usually on the $x$ axis), and the other is considered to be a dependent variable (usually on the $y$ axis). The explanatory variable is the thing you are changing or controlling in the experiment, the dependent variable is your primary measurement. For example, in the experiment today you will acquire and plot velocity versus time data which is predicted to obey a linear relationship of the form $v\!=\!v_o + a_ot$ where $a_o\!=\!-g$ is the constant acceleration and $v_o$ the initial velocity. \\

If the data {\it look} linear, and it seems like we could draw a straight line through at least most of the data \ldots how do we find the best possible line to draw? That is, what is the equation of a straight line that has the minimum total deviation from the actual data set? Further, how well does this line describe our data (i.e., how close is our data to being linear)? The line of best fit is often called a ``fit'' or ``trendline,'' and if it is a good enough fit to the data, it allows us to model a large data set approximately by a simple linear relationship. In the present experiment, the slope of this line will yield the coefficient of restitution. \\

Let our experimental data set be $x_i$ and $y_i$, a collection of $x$ and $y$ values. Our first data point is $i=1$, $(x_1,y_1)$, and the fifth is $(x_5,y_5)$. The trend line we seek can be described by

\begin{equation}
y_{\text{fit}} = mx + b
\end{equation}

\noindent Once we determine the proper slope $m$ and intercept $b$ for our trendline, we can plug in a value for our explanatory variable $x$ and the equation predicts a value for our dependent variable $y_{\text{fit}}$. If we choose to plug in the same $x$ values as in our experiment, the corresponding values of $y_{\text{fit}}$ will not necessarily match the data exactly for all points. Rather, the best fit trendline is the {\em the one that minimizes the overall differences between the trendline and the data.}

\subsection{Calculating the best-fit trendline}

Finding the line of best fit is not terribly different from calculating standard deviation, as we did in the previous experiment. The basic idea is that rather than calculating the standard deviation with respect to the mean (average) value of the data, we calculate the standard deviation with respect to an arbitrary {\em line} drawn through the data. Recall the definition of standard deviation:

\begin{equation}
\sigma = \sqrt{\frac{1}{n-1}\sum\limits_{i=1}^n \left(x_i-\overline{x}\right)^2} \label{eq:std-dev}
\end{equation}

A descriptive version of the equation might go like this:

\begin{equation}
\sigma = \sqrt{\frac{1}{\text{num.\ points }-1} \sum\limits_{i=1}^{\text{num.\ points}} \left(\text{data point} - \text{average}\right)^2}
\end{equation}

If we want to calculate the deviation from a {\em line} instead of the average, we would do this:

\begin{equation}
(\text{deviation}) = \sqrt{\frac{1}{\text{num.\ points }-1} \sum\limits_{i=1}^{\text{num.\ points}} \left(\text{data point} - \text{line}\right)^2}
\end{equation}

Or, using our equation for the trend line,

\begin{equation}
(\text{deviation}) = \sqrt{\frac{1}{n-1}\sum\limits_{i=1}^n \left(x_i-mx - b \right)^2}
\end{equation}

The best possible trend line is the one that {\em minimizes} this overall deviation. Performing the minimization requires the use of calculus, but the result is simple enough. How do we calculate the best-fit trendline? First, you will need a data table: your $x$ and $y$ values, their squares, and their products. Something like the table below; we have included two header columns to give you a better idea of what is going on.\\

\begin{table}[h]\centering
\caption{Data table}
\begin{tabular}{crrrrr@{}} \toprule[1.5pt]
$i$ & \multicolumn{1}{c}{$x_i$} & \multicolumn{1}{c}{$y_i$} & \multicolumn{1}{c}{$x_i^2$} & \multicolumn{1}{c}{$y_i^2$} & \multicolumn{1}{c}{$x_i y_i$} \\   \midrule
1 & 2 & 4.7 & 4 & 22.09 & 9.4 \\
2 & 3 & 7.1 & 9 & 50.41 & 21.3\\
3 & 5 & 11.2 & 25 & 125.44 & 56.0\\
4 & 7 & 14.7 & 49 & 216.09 & 102.9	\\ \bottomrule[1.5pt]
{\bf totals} & 17 & 37.7& 87 & 414.03 &189.6\\
{\bf average} & 4.25 & 9.425 & - & - & - \\
\end{tabular}
\end{table} 

The sums are easily performed in Excel; if you do not know how to do this, ask your neighbors or your TA. Now we have enough data tabulated to determine the line of best fit to our experimental data. Again, the derivation of how this works is beyond the scope of our discussion, but the quantities calculated above are enough:
\begin{align}
m &= \text{trendline slope}  = \frac{(\text{sum of $x$ times $y$ column})-\left(\text{num.\ points}\right)\left(x \text{ average}\right)\left(y \text{ average}\right)}{\left(\text{sum of $x^2$ column}\right) - \left(\text{num.\ points}\right)\left(\text{x average}\right)^2} \nonumber\\
m&= \frac{\left(\sum\limits_{i=1}^{i=n} x_iy_i\right) - n \overline{x}\, \overline{y}}{\left(\sum\limits_{i=1}^{i=n} x_i^2\right) - n\overline{x}^2}
\end{align}

Here the sums are defined as last time; the one in the numerator is the total of the column $x_iy_i$, the one in the numerator is the total of the $x_i^2$ column. The averages of all $x$ and $y$ values are $\overline{x}$ and $\overline{y}$, respectively, and $n$ is the total number of data points. For our data, we have
\begin{equation}
m = \frac{189.6 - 4\times4.25\times9.425}{87 - 4\times4.25^2} \approx 1.99
\end{equation}

The intercept is found more easily if we already have the slope:\footnote{We should note that one can also calculate the uncertainty or {\em confidence interval} for the slope and intercept, a measure of how reliable the extracted trendline parameters are. This is a little more difficult and nuanced, and we will not dwell on it. Be aware that the trendline parameters are merely {\em best fit} values -- in any particular case, however, even the `best fit' can be pretty terrible! The correlation coefficient, discussed below and reported by most programs like Excel or DataStudio, is a simple way to judge the quality of the trendline in describing your data.}
\begin{equation}
b = \text{trendline intercept} = \overline{y} - m\,\overline{x} = 9.425 - 1.99\times4.25 \approx 0.968
\end{equation}

Of course, these parameters $m$ and $b$ describing the trend line have uncertainties, which can be calculated. This is somewhat tedious, however, so we will leave that for a later experiment \ldots

A neat fact is that trend line must pass through the dataset average point $(\overline{x},\overline{y})$. Here is a plot of our data and the calculated trendline:

\begin{figure}[h] 
\centering
	\includegraphics[width=0.65\linewidth]{reg.pdf}
\end{figure}



It is quite good! But how good? 

\subsection{Correlation coefficient}

We can also define (but will not derive) a ``goodness of fit'' parameter $r$. If $r\!=\!0$, there is no correlation between $x$ and $y$ -- total randomness. If $r\!=\!-1$, the data are perfectly {\it negatively} correlated -- a line with negative slope. If $r\!=\!+1$, the data is perfectly {\it positively} correlated -- a line with positive slope. The closer $|r|$ is to $1$, the better the correlation, while a small value of $|r|$ near zero indicates poor correlation. We would guess that our $r$ should be positive, and close to $1$ based on the plot above. Here's how we calculate $r$, using the same data table we already generated:

\begin{equation}
\text{quality of fit} = r = \frac{n \left(\sum\limits_{i=1}^{i=n} x_iy_i\right) - \left(\sum\limits_{i=1}^{i=n} x_i\right)\left(\sum\limits_{i=1}^{i=n} y_i\right)}{\sqrt{n\left(\sum\limits_{i=1}^{i=n} x_i^2\right) - \left(\sum\limits_{i=1}^{i=n} x_i\right)^2}\sqrt{n\left(\sum\limits_{i=1}^{i=n} y_i^2\right) - \left(\sum\limits_{i=1}^{i=n} y_i\right)^2}}
\end{equation}

It is a bit fearsome-looking, and we will use Excel to calculate it automatically in general, but it just involves sums we've already done. In our case,

\begin{equation}
r = \frac{4\times189.6 - 17\times 37.7}{\sqrt{4\times87 - 17^2}\sqrt{4\times414.03 - 37.7^2}} \approx 0.998
\end{equation}

Almost perfect positive correlation. Of course, real data is often not quite this good; if you find $r\!\approx\!0.8\!-\!0.9$ consider it a good day. We should note that usually programs like Excel tell you $r^2$ rather than $r$; the main operational difference is that $r^2\!=\!1$ for perfect correlation, and $r^2\!=\!0$ when there is no linear correlation.\\

Finally, both the trendline generation and quality of fit estimate can be done automatically for a given plot in Excel and DataStudio! Now that you've done it manually, it is no longer just another magic feature: it is based on solid mathematics. One note in passing, Excel will report $r^2$ rather than $r$ for the quality of the fit. Values of $r^2$ extend from $0$ to $1$, with $0$ being no correlation, and $1$ being perfect correlation. \\

%%%%%%%%%%%%%%%%%%%%

\subsection{Linearization of a non-linear relationship}

Based on our discussions of free-fall motion, we know that the vertical position versus time for an object dropped from rest at a height $x_o$ is given by

\begin{equation}
x=\frac{1}{2}a_ot^2 + x_o = -\frac{1}{2}gt^2 + x_o
\end{equation}

\noindent Here the second form explicitly assumes that $a_o\!=\!-g$ with the upward direction defined as positive $y$. How can we make this into a linear relationship so we can make use of the regression analysis we just learned? We can start by noticing that we {\em would} have a straight line relationship if we had $t$ instead of $t^2$ in the equation above. If that is the case, all we need to do is plot $x$ versus $t^2$ instead of $x$ versus $t$, or in other words we can change the dependent variable from $t$ to $t^2$. Mathematically, we can do that by making the replacement $u\!=\!t^2$:

\begin{equation}
x=\frac{1}{2}a_ou + x_o = -\frac{1}{2}gu + x_o 
\end{equation}

\noindent Now we have a straight line of slope $-g/2$ and intercept $x_o$, and we can perform our regression analysis on the substituted data $x(u)\!=\!y(t^2)$, plotting $x$ versus $t^2$ and finding the appropriate trendline. For rather subtle statistical reasons, this procedure is {\em not} generally as accurate as if the data were linear in the first place, but it is typically a very good way to estimate the best-fit parameters for a non-linear relationship.\\

As another example, let's say we had an exponential relationship, like this:

\begin{equation}
x = x_o e^{-at}
\end{equation}

% PLOT EXAMPLE OF LINEARIZED DATA

\noindent In this case, we could linearize the equation by taking the natural logarithm of each side and re-arranging:

\begin{equation}
\ln{x} = -at + \ln{x_o}
\end{equation}

\noindent Now if we plot $\ln{y}$ versus $t$ we should get a straight line of slope $-a$ and intercept $\ln{x_o}$. Not every equation can be linearized in a simple way, but the general trick is one we will use quite often in introductory physics. 

% WHY THIS IS NOT TOTALLY COOL FOR A BEST FIT LINE, BUT GOOD ENOUGH FOR AN ESTIMATE

%%%%%%%%%%%%

%\subsection{Correlation versus Causation}

%STOLEN paragraph for info:

%Explanatory variables may �explain� the dependent variable well, but this does not necessarily imply a causal link. This highlights the problem with �data mining�, where many many relationships are tested to see which one has the best �fit�. A high fit does not necessarily mean that the essential structure of the relationship between two or more variables has been accu- rately modeled. This makes it extremely difficult to use the model for any sort of predictions.
%The most appropriate way to select a model is to first use basic princi- ples or theory to construct a structural relationship between the variables of interest. For example, just because chicken production and global CO2 measurements are nearly perfectly correlated over time, doesn�t mean that if chicken production increases in the future, so will global CO2.
%True causality is extremely difficult to tease out statistically. One method is called �Granger Causality�, which essentially asks whether the explanatory variable happens prior to the dependent variable; if so, a causal link is more defensible. We won�t go into a great deal of detail on this subject, but it is important to remember that correlation does not imply causation.

%%%%%%%%%%%

\vfill \clearpage

\section{Preparatory Questions}

Comment on these questions in your report.

% calc mean, stdev, stdev of mean for a set of data

\begin{my-enumerate}
\item Sketch what you expect the velocity versus time graph for a falling ball to look like.
\item Sketch the corresponding acceleration and position versus time graphs for a falling ball.
\item What do you think the influence of air resistance would be? 
\item Make $x\!-\!y$ plots of the four data sets below and find the best fit trendline for each. What does this tell you about the limitations of purely statistical analysis?\footnote{These four datasets are known as ``Anscomb's quartet,'' specifically designed to have identical simple statistical properties. see \url{http://en.wikipedia.org/wiki/Anscombe's_quartet} for more information.} {\em There is an excel file downloadable at \url{http://faculty.mint.ua.edu/~pleclair/ph101/labs/Lab2_falling-object/} with this data already entered. The preceding link should be clickable, by the way.}
\item Investigate the applet at \url{http://hadm.sph.sc.edu/courses/J716/demos/leastsquares/leastsquaresdemo.html}
\end{my-enumerate}

\begin{table}[h]\centering
\begin{tabular}{rrcrrcrrcrr@{}} \toprule[1.5pt]
\multicolumn{2}{c}{{\bf Data set 1}}&$\quad$&  \multicolumn{2}{c}{{\bf Data set 2}} &$\quad$&  \multicolumn{2}{c}{{\bf Data set 3}} &$\quad$&  \multicolumn{2}{c}{{\bf Data set 4}}\\\cmidrule{1-2}\cmidrule{4-5}\cmidrule{7-8}\cmidrule{10-11}
 \multicolumn{1}{c}{$x$}  & $y\,\,\,$ &&  \multicolumn{1}{c}{$x$}  & $y\,\,\,$ &&  \multicolumn{1}{c}{$x$}  & $y\,\,\,$&&  \multicolumn{1}{c}{$x$}  & $y\,\,\,$ \\ \midrule
10	& 8.04 &&	10&	9.14 &&10 & 7.46 && 8 & 6.58\\
8	& 6.95 &&	8 &	8.14 && 8 & 6.77 && 8 & 5.76\\
13	& 7.58 &&	13 &	8.74 && 13 & 12.74 && 8 & 7.71\\
9	& 8.81 &&	9 &	8.77  && 9 & 7.11 && 8 & 8.84\\
11	& 8.33 &&	11 &	9.26 && 11 & 7.81 && 8 & 8.47\\
14	& 9.96 &&	14 &	8.10 && 14 & 8.84  && 8 & 7.04\\
6	& 7.24 &&	6 &	6.13 && 6 & 6.08 && 7 & 5.24\\
4	& 4.26 &&	4 & 	3.10  && 4 & 5.39 && 19 & 12.5\\
12	& 10.84 &&	12 &	9.13&& 12 & 8.15 && 8 & 5.56\\
7	& 4.82 &&	7 &	7.26 && 7 & 6.42 && 8 & 7.91\\
5	& 5.68 &&	5 &	4.74 && 5 & 5.73 && 8 & 6.89\\ \bottomrule[1.5pt]
\end{tabular}
\caption{Four example data sets for analysis.}
\end{table}

%%%%%%%%%%

\section{Relevant Reading} 

Young, {\em College Physics} 9$^{\text{th}}$ edition, Ch.~2

\section{Supplies \& Equipment}

\begin{my-enumerate}
\item Computer with DataStudio, sensor interface, Excel
\item Rubber ball
\item Group of 2-4 students
\end{my-enumerate}

%%%%%%%%%%%%%
\section{Suggested Procedure}

Now we'll compare your predictions to experiment. {\bf To start the experiment:}

\begin{my-enumerate}
\item Mount the motion sensor on a stand a meter or so above the table if it is not already.
\item Orient the sensor so that the ultrasonic beam will be projected downward.\footnote{Note also the beam width selector switch on the back - narrow or wide beam. It should be set to narrow beam.}
\item Open Data Studio, select ``Create Experiment.''
\item Select ``Motion Sensor'' under the list of sensors. Drag it to the interface box on the right side. When you are over the correct connections they will become highlighted; let go when this happens.
\item Plug the sensor connections (color coded) into the interface as now shown on the screen.
\item Double click on the motion sensor icon that is shown connected to the interface, select the Motion Sensor tab, and set the trigger rate (it may be called the 'sample rate') to 100.
\end{my-enumerate}

{\bf Making plots and taking data:}

\begin{my-enumerate}
\item On the left-hand side of the screen at the bottom, double click on `graph' to create a graph.
\item Select the data you wish to have on the $y$ axis (position, velocity, or acceleration). Choose position to start with, you can add a velocity graph later. 
\item Alternatively, in the upper right side of the screen, there is a list of available data. Drag `position' to the `graph' icon on the lower left of the screen, and a position-time graph should appear.
\item Hit ``start'' and ``stop'' to collect position data. While the data collection is running, you can verify that the sensor is working by moving your hand in front of it. {\em Note that the sensor measures position relative to itself.}
\item Once data has been collected, you can drag data from different `runs' onto an existing graph or create a new one. You can also drag velocity data onto an existing position-time plot, and velocity-time plot will show up on the same graph.
\item During any given run, position, velocity, and acceleration data are {\em all} collected. You do not need to do a separate run to record velocity and position, you can always plot both from a given run.
\item Zooming, scaling, and so on should be straightforward - play with the controls a bit!
\end{my-enumerate}

{\bf Experiment 1:}

\begin{my-enumerate}
\item  Record the motion of the ball as it is dropped from about 20 cm below the motion sensor onto the table.  
\item Try to record the motion of the ball as it bounces at least three times.  You may need to attempt this a few times.  If the ball drifts out of the ultrasonic beam as it bounces, the sensor will not detect its motion. 
\item What differences and similarities do you observe between the measured position and your predicted graph? Can you explain the differences?  
\item  Now we want to think about the velocity of this ball.  You already sketched what you think the velocity versus time graph will look like.  Compare your description with your neighbors�, and try to reach a consensus.  Sketch your consensus prediction. What is the mathematical relationship between the position and velocity graphs?
\item Double click on ``Graph'' under ``Displays'' and drag velocity (under Data) onto the position graph so that you have simultaneous plots of position and velocity. Click the appropriate button on the menu bar to align and match the horizontal axes of the graphs. Does your velocity graph look the way you expected?  Explain any differences you see.
\item You can also use the ``slope tool'' to find the slope of the position-time curve at any point. How does this slope compare to the measured velocity?
\item You also predicted what you think the acceleration graph will look like. Compare with your neighbors, and try to reach a consensus.  Make a new sketch if necessary when you reach a consensus.
\item Drag acceleration over to the graph as you did with velocity, and see if your prediction was correct.  Discuss any differences you observe.
\item  Let us describe these graphs mathematically.  Look first at the standard equations for a body in free fall, to see how you might determine the acceleration of the ball from these equations.  Select a time interval between bounces; highlight those data points. 
\item Fit the position data to a {\bf quadratic equation} and determine the acceleration of gravity from your fit parameters.  Do this by clicking on the small ``Fit'' button and choose ``quadratic.''  
\item Likewise, fit the velocity data between bounces to a {\bf linear} equation and determine the acceleration of gravity.  Note that the standard deviation (uncertainty) for slope and intercept are reported for linear fits, as is the correlation coefficient $r$. report your acceleration as the slope plus or minus the standard deviation.
\item Now find the average acceleration of the ball during this time interval from the acceleration graph. (To find the average of a set of data points, click on the ``$\Sigma$'' button and choose ``mean.'') You can also display the standard deviation $\sigma$ and number of points $n$. Report the acceleration with uncertainty, the latter determined by $\sigma/\sqrt{n}$.
\end{my-enumerate}

{\bf Experiment 2:}

\begin{my-enumerate}
\item When air friction is present, the equation for $x(t)$ as a function of time becomes:
\begin{equation}
x(t) = \frac{v_t^2}{g} \left(e^{-gt/v_t} - 1\right) + v_t t
\end{equation}
 where $v_t$  is the terminal velocity. For long times ($t\!\gg\!v_t/g$) the first part of the equation is negligible and 
$x(t)\!\approx\!v_t t$. For some objects (such as a feather), the terminal velocity is sufficiently small such that when dropped, they reach the terminal velocity in a very short distance. 
\item Take a coffee filter (or several stacked together); let it fall to the ground. Plot both its position and velocity as function of time and calculate its final velocity from both graphs. Comment on how the position, velocity, and acceleration graphs are different compared to the free-fall motion of the ball (for which air resistance is negligible).
\end{my-enumerate}

%%%%%%%%%%%%%
\section{Discussion Topics for Report}

These are questions you should address in your report, in addition to the preparatory questions and the questions embedded in the experimental procedure above. You should also include printouts of the position, velocity, and acceleration graphs showing the fits (position and velocity) and averaging (acceleration). 

\begin{itemize}
\item Are the accelerations determined from $x(t)$ and $v(t)$ of the same magnitude? 
\item  Do they have the same direction? 
\item Which experimental data gives the best estimate for $g$? Why?
\item Can you {\em quantify} the uncertainty in your data?
\end{itemize}

%%%%%%%%%%%%%
\section{Format of Report}

Your report need not be formal, the format is largely up to you. Answer all the questions above, turn in the plots you were asked to make, and your overall conclusions. Address the discussion topics briefly. 


\end{document}
