from numpy import *
import matplotlib.pyplot as plt


om1 = 10.
om2 = 11.
phi1 = 0.
phi2 = 0.
max_time = 3*(om1+om2)/2*2.*pi/maximum(om1,om2)

def y1(t,om1,om2,phi1,phi2):
    return cos(((om1-om2)/2)*t+(phi1-phi2)/2)*cos(((om1+om2)/2)*t + (phi1+phi2)/2)

def env1(t,om1,om2,phi1,phi2):
    return cos(((om1-om2)/2)*t+(phi1-phi2)/2)

def y2(t,om1,om2,phi1,phi2):
    return sin(((om1-om2)/2)*t+(phi1-phi2)/2)*sin(((om1+om2)/2)*t + (phi1+phi2)/2)

def env2(t,om1,om2,phi1,phi2):
    return sin(((om1-om2)/2)*t+(phi1-phi2)/2)

t = linspace(0,max_time,500)


fig, (ax1,ax2) = plt.subplots(2,sharex=True,figsize=(20,5))
ax1.plot(t,y1(t,om1,om2,phi1,phi2),lw=3,color='k',label=r'x1(t)')
ax2.plot(t,y2(t,om1,om2,phi1,phi2),lw=3,color='r',label=r'x2(t)')
ax1.plot(t,env1(t,om1,om2,phi1,phi2),lw=3,color='k',linestyle=':')
ax1.plot(t,-env1(t,om1,om2,phi1,phi2),lw=3,color='k',linestyle=':')
ax2.plot(t,env2(t,om1,om2,phi1,phi2),lw=3,color='r',linestyle=':')
ax2.plot(t,-env2(t,om1,om2,phi1,phi2),lw=3,color='r',linestyle=':')
ax2.set_xlabel(r'Zeit [$1/\omega$]',fontsize=20)
ax1.set_ylabel('Amplitude',fontsize=20)
ax2.set_ylabel('Amplitude',fontsize=20)
ax1.tick_params(labelsize=18)
ax2.tick_params(labelsize=18)
ax1.legend(loc='upper right',fontsize=20)
ax2.legend(loc='upper right',fontsize=20)
for ax in (ax1,ax2):
    ax.label_outer()
plt.subplots_adjust(hspace=0)
plt.tight_layout()
plt.savefig('gekoppeltes-pendel.eps')
plt.show()
