def calc_g(self,e): if self.data.points == []: return x = self.lentext.get() try: L = float(x) except: self.msgwin.msg('Set the length of the rod', 'red') return import phmath, math dat = [] for k in self.data.points: dat.append([k[0], k[1]]) res = phmath.fit_dsine(dat) fit = [] exp = [] for k in res[0]: fit.append([k[0],k[2]]) exp.append([k[0],k[3]]) self.data.traces.append(fit) self.col = self.data.get_col() self.plot2d.line(fit, self.col) self.col = self.data.get_col() self.plot2d.line(exp, self.col) D = res[1][4] T = 1.0 / res[1][1] r = 0.14 # radius of the rod R = 1.27 # radius of the ball density = 7.8 # density of iron m_rod = math.pi * r**2 * L * density m_ball = math.pi * 4 / 3 * R**3 * density # print m_rod,'',m_ball Lprime = ( (m_rod * L**2)/3 + (m_ball * 2/5 * R**2) + m_ball * \ (L+R)**2 ) / ( (m_rod * L)/2 + m_ball*(L+R) ) g = 4.0 * math.pi**2 * Lprime / (T * T) # print T, Lprime, g, D ss = 'T = %4.3f seconds. Length = %4.2f | g = %4.0f \ cm/sec2 | Damping factor = %4.3f\n'%(T,L,g,D) self.msgwin.showtext(ss)
import phm, phmath p=phm.phm() ifp=open('pend.dat','r') data = [] while 1: a = ifp.readline() if len(a) < 3: break ss = a.split() data.append( [float(ss[0]), float(ss[1])]) res = phmath.fit_dsine(data) frfit = res[1][1]*1.0e6 print frfit p.plot(res[0]) p.save_data(res[0]) p.set_scale(0,-5,5,5) raw_input()