Search
An in-class example

An in-class interactive demo on uncertainty

Everyone in class will use the stopwatch on their phone to measure time between Start and Stop. We will watch these three videos

Enter your data here along with : https://goo.gl/npNx1J

from IPython.display import HTML
HTML("""
<div align="middle">
<video controls>
      <source src="/intro-exp-phys-book/images/start_stop_animation.m4v" type="video/mp4">
</video></div>""")
HTML("""
<div align="middle">
<video controls>
      <source src="/intro-exp-phys-book/images/start_stop_animation_with_countdown_movie.m4v" type="video/mp4">
</video></div>""")
HTML("""
<div align="middle">
<video controls>
      <source src="/intro-exp-phys-book/images/start_stop_animation_with_double_countdown.m4v" type="video/mp4">
</video></div>""")

Now let's analyze the data

The Data is here: https://goo.gl/npNx1J

We will just copy and paste it from google docs into this notebook

import numpy as np
import matplotlib.pyplot as plt
temp1 = """
7.48
7.62
7.59
7.55
7.5
7.53
7.56
7.88
7.5
7.63
7.59
7.55
7.62
7.32
7.58
7.8
7.53
7.59
7.54
7.84
8.71
7.6
7.61
7.57
7.52
7.66
7.89
"""
temp2 = """
7.84
7.62
7.8
7.66
7.6
7.63
7.9
7.66
7.73
7.58
7.62
7.69
8.21
7.57
7.56
7.72
7.66
7.53
7.83
7.7
7.71
7.65
7.72
7.72
7.84
7.89
7.83
"""
# you can split the lines into a list, but entries are still treated like text
temp1.split()
['7.48',
 '7.62',
 '7.59',
 '7.55',
 '7.5',
 '7.53',
 '7.56',
 '7.88',
 '7.5',
 '7.63',
 '7.59',
 '7.55',
 '7.62',
 '7.32',
 '7.58',
 '7.8',
 '7.53',
 '7.59',
 '7.54',
 '7.84',
 '8.71',
 '7.6',
 '7.61',
 '7.57',
 '7.52',
 '7.66',
 '7.89']
# here we will convert into numpy arrays 
x1 = np.array(temp1.split()).astype(np.float)
x1
x2 = np.array(temp2.split()).astype(np.float)
x2
array([7.84, 7.62, 7.8 , 7.66, 7.6 , 7.63, 7.9 , 7.66, 7.73, 7.58, 7.62,
       7.69, 8.21, 7.57, 7.56, 7.72, 7.66, 7.53, 7.83, 7.7 , 7.71, 7.65,
       7.72, 7.72, 7.84, 7.89, 7.83])
# We can also plot data. 
# What are the horizontal and vertical axes?
# Is this a good way to display the data?
plt.plot(x1)
plt.plot(x2)
[<matplotlib.lines.Line2D at 0x7fbfd0b806a0>]
# An alternate pesentation
plt.hist(x1, bins=30)
(array([1., 0., 0., 3., 6., 6., 5., 1., 0., 0., 1., 1., 2., 0., 0., 0., 0.,
        0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1.]),
 array([7.32      , 7.36633333, 7.41266667, 7.459     , 7.50533333,
        7.55166667, 7.598     , 7.64433333, 7.69066667, 7.737     ,
        7.78333333, 7.82966667, 7.876     , 7.92233333, 7.96866667,
        8.015     , 8.06133333, 8.10766667, 8.154     , 8.20033333,
        8.24666667, 8.293     , 8.33933333, 8.38566667, 8.432     ,
        8.47833333, 8.52466667, 8.571     , 8.61733333, 8.66366667,
        8.71      ]),
 <a list of 30 Patch objects>)
np.mean(x1)
7.6429629629629625
np.std(x1)
0.24256064251012488
np.mean(x2)
7.721111111111111
np.std(x2)
0.13934591472525237
plt.hist(x2, bins=30)
(array([1., 2., 1., 3., 1., 4., 0., 3., 4., 0., 0., 1., 0., 4., 0., 1., 1.,
        0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1.]),
 array([7.53      , 7.55266667, 7.57533333, 7.598     , 7.62066667,
        7.64333333, 7.666     , 7.68866667, 7.71133333, 7.734     ,
        7.75666667, 7.77933333, 7.802     , 7.82466667, 7.84733333,
        7.87      , 7.89266667, 7.91533333, 7.938     , 7.96066667,
        7.98333333, 8.006     , 8.02866667, 8.05133333, 8.074     ,
        8.09666667, 8.11933333, 8.142     , 8.16466667, 8.18733333,
        8.21      ]),
 <a list of 30 Patch objects>)
plt.scatter(x1,x2)
plt.xlim()
(7.240643369175627, 8.789356630824372)
x1.size, x2.size
(27, 27)
mybins = np.linspace(7.4,8.5,20)
plt.hist(x1, bins=mybins, alpha=.3,label='first')
plt.hist(x2, bins=mybins, alpha=.3,label='second')
plt.legend()
plt.xlabel('time')
plt.ylabel('counts')
Text(0, 0.5, 'counts')
plt.xlim(7.3,7.8)
plt.ylim(7.3,7.8)
plt.scatter(x1,x2)
plt.axvline(x=7.5)
plt.axhline(y=7.5)
<matplotlib.lines.Line2D at 0x7fbfe8a2a160>
plt.Line2D([7.5, 7.5], [7.3, 7.8], linewidth=2)
<matplotlib.lines.Line2D at 0x7fbfe8ad92e8>