Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python2
- # script for solving g from pendulum experiment ( http://physics.stackexchange.com/q/106531/43812 )
- # - LENGTH => length of the string
- # - g => constant (used for solving T - not needed, just a test)
- # - data => data obtained from the experiment - [[T_0,alpha_0],[T_1,alpha_1],..]
- # - PRECISION => precision of the sum, since we can't count to infinity (yet)
- # Output for this setup:
- # Running test
- # Average T: 1.18953233488
- # Average g: 9.40189803166
- from math import *
- LENGTH = 0.31
- G = 9.81
- data=[[1.15, 11.54], [1.16, 26.57], [1.18, 39.49], [1.18, 44.11], [1.2, 52.15], [1.22, 58.29], [1.23, 63.96], [1.25, 66.53], [1.28, 73.78], [1.3, 83.54]]
- PRECISION = 80
- SUM = lambda alpha:sum([(factorial(2.*n) / (2.**n*factorial(n))**2 )**2 * sin(radians(alpha)/2)**(2*n) for n in xrange(PRECISION)])
- t = lambda alpha, length=LENGTH, g=G: 2.*pi*sqrt(length/g)*SUM(alpha)
- g = lambda alpha, period, length=LENGTH: ((2*pi*SUM(alpha))/(period))**2 * length
- if __name__=="__main__":
- print("Running test")
- all_t=[ t(i[1]) for i in data ]
- print("Average T: {0}".format(sum(all_t)/len(all_t)))
- all_g=[ g(i[1],i[0]) for i in data ]
- print("Average g: {0}".format(sum(all_g)/len(all_g)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement