Professional Documents
Culture Documents
s1 = 0.5
d1 = 1.0
s2 = 0.5
d2 = 1.0
k1 = 0.5*s1
k2 = 0.5*s2
m1 = 1.0
m2 = 1.0
g = 9.81
z0 = [1.02*0.8*pi,0.0,-0.0*pi,0.0]
N=600
tend = 10.0
toutput = np.linspace(0.0,tend,N)
def appellpendel(a,z,t):
phi1tt = a[0]
phi2tt = a[1]
phi1 = z[0]
phi1t = z[1]
phi2 = z[2]
phi2t = z[3]
def rhspendel(z,t):
phi1 = z[0]
phi1t = z[1]
phi2 = z[2]
phi2t = z[3]
c = appellpendel([0,0],z,t)
S1 = appellpendel([1,0],z,t)
S2 = appellpendel([-1,0],z,t)
a11 = 0.5*(S1 + S2) - c
b1 = 0.5*(S1-S2)
S1 = appellpendel([0,1],z,t)
https://lms.bht-berlin.de/mod/page/view.php?id=929278 1/3
04.02.23, 20:18 22W_TM3_MB-CED: Python-Code für die Animation des Doppelpendels
S2 = appellpendel([0,-1],z,t)
a22 = 0.5*(S1 + S2) - c
b2 = 0.5*(S1-S2)
a12 = appellpendel([1,1],z,t) -a11 - a22 - b1 - b2 - c
ergebnis = odeint(rhspendel,z0,toutput)
phi1_tab = ergebnis[ : , 0]
omega1_tab = ergebnis[ : , 1]
phi2_tab = ergebnis[ : , 2]
omega2_tab = ergebnis[ : , 3]
xD1 = d1*np.sin(phi1_tab)
yD1 = -d1*np.cos(phi1_tab)
xD2 = xD1 + d2*np.sin(phi2_tab)
yD2 = yD1 - d2*np.cos(phi2_tab)
plt.figure(1)
plt.plot(xD1, yD1,"b-",linewidth=2)
plt.plot(xD2, yD2,"r--")
plt.axis('equal')
plt.xlabel("$x$")
plt.ylabel("$y$")
plt.savefig('tm3-dy-doppelpendel-D1D2_2.pdf')
#plt.show()
#Animation
fig = plt.figure(2)
ax = fig.add_subplot(
111,
autoscale_on=False,
xlim=(-d1-d2,d1+d2),
ylim=(-d1-d2, d1+d2),
aspect='equal'
)
ax.axhline(color='0.6', linestyle='dashed')
def animate(i):
x = [0,xD1[i],xD2[i]]
y = [0,yD1[i],yD2[i]]
line1.set_data(x, y)
line2.set_data(xD2[0:i],yD2[0:i])
return line1, line2
plt.tight_layout()
if 'save' in sys.argv:
ani = animation.FuncAnimation(fig, animate, range(N), interval=25)
ani.save('doppelpendel_var2.gif', dpi=80, writer='pillow') #ani.save('kurbelschwinge.gif', dpi=80, writer='imagemagick')
else:
ani = animation.FuncAnimation(fig, animate, range(N), interval=30,repeat_delay=2000)
plt.show()
https://lms.bht-berlin.de/mod/page/view.php?id=929278 2/3
04.02.23, 20:18 22W_TM3_MB-CED: Python-Code für die Animation des Doppelpendels
Seguir para...
Berliner Hochschule für Technik | Datenschutz- und Einwilligungserklärung | Hinweise zum Urheberrecht | Impressum
https://lms.bht-berlin.de/mod/page/view.php?id=929278 3/3