Skip to content

Instantly share code, notes, and snippets.

@BayMinimum
Created November 17, 2018 06:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BayMinimum/2fe3f5490ecd8912a922783409a27631 to your computer and use it in GitHub Desktop.
Save BayMinimum/2fe3f5490ecd8912a922783409a27631 to your computer and use it in GitHub Desktop.
Simple Harmonic Oscillator
# Output graph of a simple harmonic oscillator
import numpy as np
import matplotlib.pyplot as plot
def x(A, omega_0, phi_0, t):
return A * np.cos(omega_0*t + phi_0)
x_0, v_0 = 5.0, 15.0
m, c = 0.5, 0.8
k = 5.0
omega_0 = np.sqrt(k/m)
phi_0 = - np.arctan(v_0 / (omega_0 * x_0))
A = x_0 / np.cos(phi_0)
t = np.arange(0.0, 10.0, 0.01)
plot.xlabel('t')
plot.ylabel('x')
plot.plot(t, x(A, omega_0, phi_0, t), lw=2)
plot.savefig('sho.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment