description Link to heading

  • Equation of motion of a damped oscillation $$\tag{1} \ddot{x} + 2 \gamma \dot{x} + \omega^2 x = 0. $$
  • Numerical approach using Finite Difference $$\tag{2} f(t + \Delta t) = f(t) + \frac{df(t)}{dt} \Delta t. $$
  • Solution for $x$ if $\gamma \ne \gamma(t)$ and $\omega \ne \omega(t)$.
  • To find suitable $\Delta t$.

formulation Link to heading

  • Time $$\tag{7} t_{n+1} = t_n + \Delta t, \ \ \ n = 0, 1, 2, \dots. $$
  • Acceleration $$\tag{4} \ddot{x}(t_n) = - 2 \gamma \dot{x}(t_n) - \omega^2 x(t_n). $$
  • Velocity $$\tag{5} \dot{x}(t_{n+1}) = \dot{x}(t_n) + \ddot{x}(t_n) \Delta t. $$
  • Position $$\tag{6} x(t_{n+1}) = x(t_n) + \dot{x}(t_n) \Delta t. $$

initial conditions Link to heading

  • Iteration $$\tag{7} n = 0. $$
  • Time $$\tag{8} t = t_0. $$
  • Velocity $$\tag{9} v(t_0) = v_0 $$
  • Posittion $$\tag{10} x(t_0) = x_0. $$

parameters Link to heading

  • Oscillation period $$\tag{11} T = 2 \pi \sqrt{\frac{m}{k}}. $$
  • Time step $$\tag{12} \Delta t \lt \lt T. $$

code Link to heading

import math

T = 1
tbeg = 0
tend = 4 * T
N = 1
dt = (tend - tbeg) / N
time = [(i*dt + tbeg) for i in range(N+1)]

k = 4 * math.pi**2
m = ( T**2 / (4 * math.pi**2) ) * k
omega = 2 * math.pi / T
gamma = 0

x0 = 1
v0 = 0

tt = []
xx = []

for t in time:
  if t == tbeg:
    v = v0
    x = x0
    a = - 2  * gamma * v - omega**2 * x
  else:
    a = - 2  * gamma * v - omega**2 * x
    v = v + a * dt
    x = x + v * dt
  
  tstr = f'{t:.3f}'
  astr = f'{a:.3f}'
  vstr = f'{v:.3f}'
  xstr = f'{x:.3f}'
  
  print("{x:", tstr, ", y:", xstr, "},", sep="")
  
  tt.append(float(tstr))
  xx.append(float(xstr))

print()
print(tt)
print(xx)

It is available at https://onecompiler.com/python/3znm4u5zv.

solution 1 Link to heading

  • $x_0 = 1$, $v_0 = 0$.
  • $T = 1$, $k = 4\pi^2$, $m = 1$.
  • $t \in [0, 4T]$, $\Delta t = 4$, $N = 1 + 1$.
  • $\gamma = 0$.

solution 2 Link to heading

  • $x_0 = 1$, $v_0 = 0$.
  • $T = 1$, $k = 4\pi^2$, $m = 1$.
  • $t \in [0, 4T]$, $\Delta t = 0.4$, $N = 10 + 1$.
  • $\gamma = 0$.

solution 3 Link to heading

  • $x_0 = 1$, $v_0 = 0$.
  • $T = 1$, $k = 4\pi^2$, $m = 1$.
  • $t \in [0, 4T]$, $\Delta t = 0.04$, $N = 100 + 1$.
  • $\gamma = 0$.

solution 4 Link to heading

  • $x_0 = 1$, $v_0 = 0$.
  • $T = 1$, $k = 4\pi^2$, $m = 1$.
  • $t \in [0, 4T]$, $\Delta t = 0.004$, $N = 1000 + 1$.
  • $\gamma = 0$.

solution 5 Link to heading

  • $x_0 = 1$, $v_0 = 0$.
  • $T = 1$, $k = 4\pi^2$, $m = 1$.
  • $t \in [0, 4T]$, $\Delta t = 0.01$, $N = 400 + 1$.
  • $\gamma = 0$.

summaries Link to heading

  • Unrealistic results are obtained for $\Delta t \ge 0.4T$.
  • Displacement could be larger than amplitude for $\Delta t = 0.04T$.
  • It is sufficient for $\Delta t = 0.01 T$.
  • It might be too fine for $\Delta t = 0.004 T$.