Words
76
Reading
1 min
Listen
Play
7y
ok so here is my solution:
import numpy as np
class calc:
def __init__(self):
self.l=1
self.dt=0.001
self.v=360
self.g=9.81
self.phi=0
self.a=1
def acc(self, gamma):
self.a= -gamma*self.v-self.g/self.l*np.sin(self.phi)
def vel(self):
self.v=self.v+self.a*self.dt
def ang(self):
self.phi=self.phi+self.v*self.dt
c=calc()
t=0
acclist=[]
vellist=[]
anglist=[]
time=[]
gamma=0.01
while t<1000:
c.acc(gamma)
c.vel()
c.ang()
t+=0.001
acclist.append(c.a)
vellist.append(c.v)
anglist.append(c.phi)
time.append(t)
print(max(anglist)/360.0)
max_time=time[anglist.index(max(anglist))]
print(max_time)
steps=[0,100]
while round(max(anglist)/360.0)!=3:
gamma=(steps[0]+steps[1])/2.0
c=calc()
t=0
anglist=[]
time=[]
while t<max_time:
c.acc(gamma)
c.vel()
c.ang()
t+=0.001
anglist.append(c.phi)
if round(max(anglist)/360)>3:
steps=[gamma,steps[1]]
else:
steps=[steps[0],gamma]
print(gamma)
c=calc()
t=0
acclist=[]
vellist=[]
anglist=[]
time=[]
while t<1000:
c.acc(gamma)
c.vel()
c.ang()
t+=0.001
acclist.append(c.a)
vellist.append(c.v)
anglist.append(c.phi)
time.append(t)
print(max(anglist)/360.0)
The output gives:
98.79413003199605
450.64399999625556
0.390625
2.536477974411837
- With gamma=0.01 the pendulum does 98 full circles
- Using simple iterations, I get a value of around 0.390625 if only 3 circles shall be completed. However, it's strange that the pendulum would stop at just above 2.5 circles, because this is just after the highest point. So maybe my calculations are wrong or at least i am very close to the lower bound
RE: Computation Contest #2 [6 SBI]