linear 1D oscillator w damping
In [1]:
import sklearn
import numpy as np
from numpy import linalg as LA
from scipy.integrate import odeint
import matplotlib.pyplot as plt
%matplotlib inline
In [44]:
Nt = 100
K = 80 ## omega0 = sqrt(k/m)
C = 0.25
A = np.array([[0,1],[-K,-C]]) # system mtx
# state: u = [x, xdot]
x0 = 1
xdot0 = 0
u0 = np.array([x0,xdot0]) # initial condition
In [22]:
T = 4
t_ = np.linspace(0,T,Nt) # time grid
In [45]:
def f(u,t):
return A.dot(u)
In [46]:
soln = odeint(f, u0, t_)
xpos = soln[:, 0]
xvel = soln[:, 1]
plt.figure()
ax = plt.subplot(111)
#plt.plot(t_,xpos,t_,xvel)
plt.plot(t_,xpos)
Out[46]:
In [ ]: