PHYS 310, HW #1, Spring 2018

In [1]:
import scipy as sp
from scipy import stats

import matplotlib as mpl       # As of July 2017 Bucknell computers use v. 2.x 
import matplotlib.pyplot as plt

# Following is an Ipython magic command that puts figures in the  notebook.
# For figures in separate windows, comment out following line and uncomment
# the next line
# Must come before defaults are changed.
%matplotlib notebook

# As of Aug. 2017 reverting to 1.x defaults.
# In 2.x text.ustex requires dvipng, texlive-latex-extra, and texlive-fonts-recommended, 
# which don't seem to be universal
# See'classic')
# M.L. modifications of matplotlib defaults using syntax of v.2.0 
# More info at
# Changes can also be put in matplotlibrc file, or effected using mpl.rcParams[]
plt.rc('figure', figsize = (6, 4.5))            # Reduces overall size of figures
plt.rc('axes', labelsize=16, titlesize=14)
plt.rc('figure', autolayout = True)             # Adjusts supblot parameters for new size

H&H Problem 2.2

Twelve data points given. Enter them into a scipy array:

In [2]:
data = sp.array([5.33, 4.95, 4.93, 5.08, 4.95, 4.96, 5.02, 4.99, 5.24, 5.25, 5.23, 5.01])

a) Calculating the mean: $\quad \mu = \frac{1}{N} \sum_i x_i$

In [3]:
print('mean = ', sum(data)/len(data))
mean =  5.07833333333


In [4]:
print('mean = ', sp.mean(data))
mean =  5.07833333333

b) Calculating standard deviation: $\quad \sigma = \sqrt{\frac{1}{N-1} \sum_i (x_i - \mu)^2}$

In [5]:
print("standard deviation = ",sp.sqrt(sum((data-sp.mean(data))**2)/(len(data)-1)))
standard deviation =  0.143579774046


In [6]:
print("standard deviation = ",sp.std(data))
standard deviation =  0.137467167797

These results do not agree!!

By default the scipy std method calculates $\sigma_N$, which is similar to the $\sigma_{N−1}$ given in Eq.(2.3) of H&H, except the denominator is $N$ instead of $N−1$. The difference doesn't usually matter, and we won't go into this in any depth now. But if we set the ddof=1 option, scipy will calculate $\sigma_{N−1}$.

Remember: you can see all the details of sp.std by typing sp.std?.

In [7]:
print("standard deviation = ",sp.std(data, ddof=1))
standard deviation =  0.143579774046

c) Standard error, or standard deviation of the mean

Use Eq.(2.7): $$\quad \alpha = \frac{\sigma_{N-1}}{\sqrt{N}}. $$

In [8]:
print("standard error =",sp.std(data,ddof=1)/sp.sqrt(len(data)))
standard error = 0.0414479105979

d) Formatted result:

Sensitivity = $5.08 \pm 0.04\, \mbox{A/W}$

H&H Problem 2.3

The standard error, or standard deviation of the mean, is given by Eq.(2.7):

$$ \alpha = \frac{\sigma_{N-1}}{\sqrt{N}}. $$

To decrease $\alpha$ by a factor of 10, the denominator must be increased by the same factor, which means that $N$ must increase by a factor of 100. Translating to the described experiment, this means that data should be collected for 100 minutes (assuming that everything in the experiment is stable for that length of time).

H&H Problem 3.5

The probabilities in this problem can be evaluated with the cumulative distribution function, or $C_{DF}$, of a normal distribution. (This $C_{DF}$ also has the name $\mbox{Erf}(x)$.) I will use the $C_{DF}$ in the scipy.stats module.

In [7]:
mean = 502
sigma = 14

Probability that the bag contains less than $500\, \mbox{g}$:

In [8]:
sp.stats.norm.cdf(500, mean, sigma)

Probability that the bag contains at least $530\, \mbox{g}$:

In [9]:
1 - sp.stats.norm.cdf(530, mean, sigma)

#4 Pendulum Problem

Data for pendulum swings:

  • Standard deviation for any set of timing measurements $= 0.04\, \mbox{s}$
  • Experiment A: 12 sets of 10 swings; average time for 10 swings $T_{10} = 28.39\, \mbox{s}$
  • Experiment B: 1 set of 120 swings; time for 120 swings $T_{120} = 340.61\, \mbox{s}$

Period from Experiment A:

The standard error (standard deviation of the mean) for the time for 10 swings is $$ \alpha = \frac{\sigma}{\sqrt{N}} = \frac{0.04}{\sqrt{12}} $$ The time for one swing is the time for 10 swings divided by 10: \begin{eqnarray} T{1} &=& \frac{T{10}}{10}\ &=& \frac{28.39 \pm \frac{0.04}{12}}{10}\ &=& 2.839 \pm \frac{0.04}{10\sqrt{12}}\ &=& 2.839 \pm 0.001155 \end{eqnarray} The presentation form of this result is $$ T_1 = 2.839\pm 0.001\, \mbox{s}. $$

Period from Experiment B:

The standard error (standard deviation of the mean) for the time for 120 swings is $$ \alpha = \frac{\sigma}{\sqrt{N}} = \frac{0.04}{\sqrt{1}} $$ The time for one swing is the time for 120 swings divided by 120: \begin{eqnarray} T{1} &=& \frac{T{120}}{120}\ &=& \frac{340.61 \pm \frac{0.04}{1}}{120}\ &=& 2.838417 \pm \frac{0.04}{120\sqrt{1}}\ &=& 2.838417 \pm 0.000333 \end{eqnarray} The presentation form of this result is $$ T_1 = 2.8384\pm 0.0003\, \mbox{s}. $$

#5 Estimating mean and standard deviation from numerical data

One method is to look for the median. There are 15 data points. The middle value is 4.19365, meaning 7 values are larger than this and 7 are smaller. The median can be a poor estimate for the mean if the distribution is very asymmetric, but these numbers go up to 4.5 and down to 3.9, so it looks like they are fairly well centered on 4.2.

Using H&H's "rough and ready" estimate (p. 11) for the standard deviation, we find that the max value minus the mean is about 0.3. Taking 2/3 of that gives a estimated standard deviation of 0.2.

#6 Estimating parameters of a Gaussian

In [ ]:
In [ ]: