Created
April 12, 2016 21:45
-
-
Save maciejczyzewski/c8d822f8bc0bf5b30d1f94c8c3ca90ba to your computer and use it in GitHub Desktop.
Measuring Gravity with a Pendulum.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import pandas as pd | |
df = pd.read_csv('grav.csv') | |
pd.set_option('display.width', 1000) | |
def t_avg(row): | |
return sum(row[0:4]) / 4 | |
df['t_avg'] = df.apply(lambda row: t_avg(row), axis=1) | |
def t_err(row): | |
t_max = max(row[0:4]); t_min = min(row[0:4]) | |
return (t_max - t_min) / 2 | |
df['t_err'] = df.apply(lambda row: t_err(row), axis=1) | |
def l_avg(row): | |
return sum(row[4:7]) / 3 | |
df['l_avg'] = df.apply(lambda row: l_avg(row), axis=1) | |
def l_err(row): | |
l_max = max(row[4:7]); l_min = min(row[4:7]) | |
return (l_max - l_min) / 2 | |
df['l_err'] = df.apply(lambda row: l_err(row), axis=1) | |
def g_avg(row): | |
L = (row['l_avg'] + 1) / 100 | |
T = row['t_avg'] / 10 | |
return (4 * ((3.14) ** 2) * L) / (T ** 2) | |
df['g_avg'] = df.apply(lambda row: g_avg(row), axis=1) | |
def g_err(row): | |
L = (row['l_avg'] + 1) / 100 | |
L_err = row['l_err'] / 100 | |
T = row['t_avg'] / 10 | |
T_err = row['t_err'] / 10 | |
return row['g_avg'] * ((L_err / L) + 2 * (T_err / T)) | |
df['g_err'] = df.apply(lambda row: g_err(row), axis=1) | |
g = sum(df['g_avg']) / 3; g_err = sum(df['g_err']) / 3 | |
p = sum(df['g_avg'][1:]) / 2; p_err = sum(df['g_err'][1:]) / 2 | |
print df | |
print "=== RESULT ===" | |
print "g = {0} +- {1} m/s^2".format(g, g_err) | |
print "g = {0} +- {1} m/s^2 (optimal)".format(p, p_err) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
t0 | t1 | t2 | t3 | l0 | l1 | l2 | |
---|---|---|---|---|---|---|---|
20.40 | 20.48 | 20.11 | 20.55 | 98 | 101 | 99 | |
24.77 | 24.72 | 24.72 | 24.41 | 149 | 151 | 150 | |
28.56 | 28.52 | 28.57 | 28.48 | 201 | 198 | 201 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Location: Szczecin, Poland