Skip to content

Instantly share code, notes, and snippets.

@maciejczyzewski
Created May 10, 2016 19:44
Show Gist options
  • Save maciejczyzewski/4108e22a29b96794338cc05c0abecd44 to your computer and use it in GitHub Desktop.
Save maciejczyzewski/4108e22a29b96794338cc05c0abecd44 to your computer and use it in GitHub Desktop.
import numpy as np
import pandas as pd
df = pd.read_csv('wach2.csv') # case 1: wach.csv, case 2: wach2.csv
pd.set_option('display.width', 1000)
m1 = 149.8; m2 = 199.6
df.columns = ['m1', 'm2']
m1_avg = df['m1'].mean()
m1_err = (df['m1'].max() - df['m1'].min()) / 2
m2_avg = df['m2'].mean()
m2_err = (df['m2'].max() - df['m2'].min()) / 2
print(m1_avg, m1_err)
print(m2_avg, m2_err)
x = (4 * (3.14 ** 2) * m1) / m1_avg ** 2
y = (4 * (3.14 ** 2) * m2) / m2_avg ** 2
print( (m1_err + m2_err )/2)
print((x + y) / 2)
print((2 * m1_err + 2 * m2_err) / 2)
def k1(row):
return ((4 * (3.14 ** 2) * m1) / (row['m1'] / 10) ** 2) / 1000
def k2(row):
return ((4 * (3.14 ** 2) * m2) / (row['m2'] / 10) ** 2) / 1000
df['k1'] = df.apply(lambda row: k1(row), axis=1)
df['k2'] = df.apply(lambda row: k2(row), axis=1)
def k_avg(row):
return (row['k1'] + row['k2']) / 2
df['k_avg'] = df.apply(lambda row: k_avg(row), axis=1)
print((df['k_avg'].max() - df['k_avg'].min()) / 2)
k_err = 1/(m1_err + m2_err)
print(df)
print("=== RESULT ===")
print("k = {0} +- {1} N/m".format(df['k_avg'].mean(), k_err))
m1, m2
5.71, 6.57
5.68, 6.79
5.67, 6.63
5.85, 6.65
5.56, 6.83
m1, m2
5.36, 5.90
5.10, 5.73
5.46, 5.70
5.33, 5.63
5.26, 5.55
5.23, 5.86
5.03, 5.51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment