Untitled

mail@pastecode.io avatar
unknown
python
2 years ago
1.2 kB
2
Indexable
Never
def exercise_12() :
    tau_pendulum = []
    tau_harmonic = []
    tau_pertubation = []
    theta0_vec = np.linspace(0.1*np.pi, 0.9*np.pi, 10000)

    integrate = VerletIntegrator()

    for i in theta0_vec:
        oscillator = Oscillator(theta0=i)
        observa = Observables()
        while np.sign(oscillator.theta)==1:
            integrate.integrate(simsystem=Harmonic(), osc=oscillator, obs=observa)
        tau_harmonic.append(oscillator.t*4)

        oscillatorPen = Oscillator(theta0=i)
        while np.sign(oscillatorPen.theta)==1:
            integrate.integrate(simsystem=Pendulum(), osc=oscillatorPen, obs=observa)
        tau_pendulum.append(oscillatorPen.t*4)

        tau_pertubation.append(2*np.pi*np.sqrt(oscillator.L/G) * (1 + 1/16*i**2 + 11/3072*i**4 + 173/737280*i**6))
    plt.figure()
    plt.plot(theta0_vec, tau_pendulum, label='Pendulum')
    plt.plot(theta0_vec, tau_harmonic, label='Harmonic')
    plt.plot(theta0_vec, tau_pertubation, label='Pertubation')
    plt.title("Comparison of Pendulum and Harmonic \n against Pertubation series")
    plt.xlabel("Theta0/pi (position)", fontsize = 12)
    plt.ylabel("T (s)", fontsize=12)
    plt.show()