Created
November 17, 2018 06:50
-
-
Save BayMinimum/2fe3f5490ecd8912a922783409a27631 to your computer and use it in GitHub Desktop.
Simple Harmonic Oscillator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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