I am trying to solve the ODE for a harmonic oscillator using Scipy's odeint solver for different dampening factors.

I'm using the following code, based off of this example:

from scipy.integrate import odeint

m = 1  # kg
k = 10  # N/m
omega = np.sqrt(k / m)

def eps(c):
  return (c / (2 * mass * np.sqrt(kspring/mass)))

def calc_deri(y, t, eps, omega):
    return (y[1], -eps * omega * y[1] - omega **2 * y[0])

time_vec = np.linspace(0, 8, 80)
yinit = (1, 0)

plt.figure(figsize=(10, 7))
for c in [1, 2, 3, 4, 5, 6]:
  eps_c = eps(c)
  yarr = odeint(calc_deri, yinit, time_vec, args=(eps_c, omega))
  plt.plot(time_vec, yarr[:, 0])


My problem is that no matter what combination of k,m, and c I use, I always get a set of curves which have very close oscillation frequencies (I can't tell from the plot whether there is no difference at all or whether the difference is so small as to not show on the graph).

Something like this:

enter image description here

But I am hoping to get something that looks more like this:

enter image description here

What am I doing wrong?

  • 1
    $\begingroup$ With the chosen values for $k$ and $m$ you get $\epsilon = \frac{c}{2\sqrt{10}}$, where the denominator is $2\sqrt{10} \simeq 6.32$. Since you are choosing $c \in \{1,2,3,4,5,6\}$ your values of $\epsilon$ are always $<1$. The modification factor for the angular frequency in this problem is $\frac{\sqrt{4-\epsilon^2}}{2}$, and for $\epsilon < 1$, this will be very close to $1$. $\endgroup$ – Christoph May 4 '20 at 7:17
  • $\begingroup$ @Christoph I tried that, but increasing values beyond 6 (for example for c in [1,3,6,9,12]) just gives me different flavors of over-damped regimes. $\endgroup$ – Alex Kinman May 4 '20 at 7:53
  • $\begingroup$ Then with a smaller value of $k$ or a larger value of $m$ the factor $\frac{1}{2} \epsilon \omega$ in the exponential term should be reduced, so that the solution doesn't decay that quickly. $\endgroup$ – Christoph May 4 '20 at 7:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.