import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import odeint
def dho(y, t, beta, omega):
    x, v = y
    dydt = [v, -2*beta*v - omega*x]
    return dydt

y0 = [1,0]
t = np.linspace(0,10,1000)
sol0 = odeint(dho, y0, t, args = (0,1))
beta=0.2
sol0_2 = odeint(dho, y0, t, args = (beta,1))
fig, ax = plt.subplots(nrows = 1, ncols = 2)
ax[0].plot(sol0[:,0], sol0[:,1])
ax[0].set_title('Beta = 0')
ax[0].set_xlabel('x')
ax[0].set_ylabel('y')
ax[1].plot(sol0_2[:,0], sol0_2[:,1])
ax[1].set_title('Beta = %2.2f' % beta)
ax[1].set_xlabel('x')
ax[1].set_ylabel('y')
fig.suptitle('Phase portrait of the damped harmonic oscillator')
fig.tight_layout()
plt.savefig("ex430.png", dpi=100)
plt.show()

Discover more from Tips and Hints for Aerospace Engineers

Subscribe now to keep reading and get access to the full archive.

Continue reading