Skip to content

Instantly share code, notes, and snippets.

@kwcooper
Created March 5, 2019 06:20
Show Gist options
  • Save kwcooper/4b23f9c4bc8c241f080d2f97ffeecf12 to your computer and use it in GitHub Desktop.
Save kwcooper/4b23f9c4bc8c241f080d2f97ffeecf12 to your computer and use it in GitHub Desktop.
Create a damped oscillation.
import math as m
import kMath as km
import matplotlib.pyplot as plt
A = .96 #initial height
ma = 5.0 #mass
k = 2.1 #spring constant
b = 0.09 #dampening
theta = 0 #phase angle
w = m.sqrt(k / ma)
l = []
for t in km.rangef(0, 100, 0.1):
x = A * (m.e ** (-b * t)) * m.cos(w * t - theta)
l.append(x)
plt.plot(l)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment