Advertisement
kecer

Pendulum

Apr 5th, 2014
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.20 KB | None | 0 0
  1. #!/usr/bin/python2
  2.  
  3. # script for solving g from pendulum experiment ( http://physics.stackexchange.com/q/106531/43812 )
  4. # - LENGTH => length of the string
  5. # - g => constant (used for solving T - not needed, just a test)
  6. # - data => data obtained from the experiment - [[T_0,alpha_0],[T_1,alpha_1],..]
  7. # - PRECISION => precision of the sum, since we can't count to infinity (yet)
  8.  
  9. # Output for this setup:
  10. # Running test
  11. # Average T: 1.18953233488
  12. # Average g: 9.40189803166
  13.  
  14. from math import *
  15.  
  16. LENGTH = 0.31
  17. G = 9.81
  18. 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]]
  19. PRECISION = 80
  20.  
  21. SUM = lambda alpha:sum([(factorial(2.*n) / (2.**n*factorial(n))**2 )**2 * sin(radians(alpha)/2)**(2*n) for n in xrange(PRECISION)])
  22. t = lambda alpha, length=LENGTH, g=G: 2.*pi*sqrt(length/g)*SUM(alpha)
  23. g = lambda alpha, period, length=LENGTH: ((2*pi*SUM(alpha))/(period))**2 * length
  24.  
  25.  
  26. if __name__=="__main__":
  27.     print("Running test")
  28.     all_t=[ t(i[1]) for i in data ]
  29.     print("Average T: {0}".format(sum(all_t)/len(all_t)))
  30.     all_g=[ g(i[1],i[0]) for i in data ]
  31.     print("Average g: {0}".format(sum(all_g)/len(all_g)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement