예제 #1
0
from dyna import forced_pendulum

omega = 2./3

dt = 2*np.pi / omega / 25

tf = 1000

acc_factors = np.linspace(1, 1.5, 100)

fft_sig = []

t = np.arange(0, tf, dt)
mask = t > 400
hann = signal.hanning(mask.sum())

for i, acc in enumerate(acc_factors):
    print i
    t, theta, theta_dot = forced_pendulum(tf, dt, np.pi/3, 0,
                        q=0.5, acc=acc, omega=omega)
    theta = theta[mask]
    theta -= theta.mean()
    theta /= np.sqrt((theta**2).mean())
    theta *= hann
    fft_sig.append(fftpack.fft(theta))


fft_sig = np.array(fft_sig)

np.save('fft_sig.npy', fft_sig)
예제 #2
0
import numpy as np
import matplotlib.pyplot as plt
from scipy import fftpack
from scipy import signal

from dyna import forced_pendulum

omega = 2.0 / 3
dt = 2 * np.pi / omega / 25
tf = 1000
acc = 1.17
eps = 1.0e-8

all_theta_signals = []

t, theta_0, theta_dot_0 = forced_pendulum(tf, dt, np.pi / 3, 0, q=0.5, acc=acc, omega=omega)
t, theta_1, theta_dot_1 = forced_pendulum(tf, dt, (1 + eps) * np.pi / 3, 0, q=0.5, acc=acc, omega=omega)

# Compute the distance between the two trajectories
dist = np.hypot(theta_1 - theta_0, theta_dot_1 - theta_dot_1)

plt.figure(figsize=(6, 4))
plt.semilogy(t, dist, lw=2)
plt.xlim(0, 400)
plt.xlabel(u"$t$", fontsize=22)
plt.ylabel("distance", fontsize=22)
plt.tight_layout()
plt.show()
예제 #3
0
import numpy as np
import matplotlib.pyplot as plt
from scipy import fftpack
from scipy import signal

from dyna import forced_pendulum

omega = 2./3
dt = 2*np.pi / omega / 25
tf = 1000
acc = 1.17
eps = 1.e-8

all_theta_signals = []

t, theta_0, theta_dot_0 = forced_pendulum(tf, dt, np.pi/3, 0,
                        q=0.5, acc=acc, omega=omega)
t, theta_1, theta_dot_1 = forced_pendulum(tf, dt, (1 + eps) * np.pi/3, 0,
                        q=0.5, acc=acc, omega=omega)

# Compute the distance between the two trajectories
dist = np.hypot(theta_1 - theta_0, theta_dot_1 - theta_dot_1)

plt.figure(figsize=(6, 4))
plt.semilogy(t, dist, lw=2)
plt.xlim(0, 400)
plt.xlabel(u'$t$', fontsize=22)
plt.ylabel('distance', fontsize=22)
plt.tight_layout()
plt.show()
예제 #4
0
omega = 2. / 3

dt = 2 * np.pi / omega / 25

tf = 1000

acc_factors = np.linspace(1, 1.5, 100)
acc_factors = acc_factors[[2, 15, 34]]

all_theta_signals = []

for i, acc in enumerate(acc_factors):
    t, theta, theta_dot = forced_pendulum(tf,
                                          dt,
                                          np.pi / 3,
                                          0,
                                          q=0.5,
                                          acc=acc,
                                          omega=omega)
    all_theta_signals.append(theta)

all_theta_signals = np.array(all_theta_signals)

mask = t > 400
theta_signals = all_theta_signals[:, mask]
theta_signals -= theta_signals.mean(axis=1)[:, np.newaxis]

theta_signals /= np.sqrt((theta_signals**2).mean(axis=1))[:, np.newaxis]

hann = signal.hanning(theta_signals.shape[1])
theta_signals *= hann
예제 #5
0
from mpl_toolkits.mplot3d import Axes3D

from dyna import forced_pendulum

fig = plt.figure()
ax = fig.gca(projection='3d')

omega = 2. / 3

dt = 2 * np.pi / omega / 100

tf = 10000

t, theta, theta_dot = forced_pendulum(1000,
                                      dt,
                                      np.pi / 3,
                                      0,
                                      q=0.5,
                                      acc=1.07,
                                      omega=omega)

mask = t > 400

ax.plot(np.mod(t[mask], 2 * np.pi / omega), theta[mask], theta_dot[mask])

ax.set_xlabel(u'$t$', fontsize=26)
ax.set_ylabel(u'$\\theta$', fontsize=26)
ax.set_zlabel(u'$\dot{\\theta}$', fontsize=26)

plt.show()
예제 #6
0
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

from dyna import forced_pendulum

fig = plt.figure()
ax = fig.gca(projection='3d')

omega = 2./3

dt = 2*np.pi / omega / 100

tf = 10000

t, theta, theta_dot = forced_pendulum(1000, dt, np.pi/3, 0,
                        q=0.5, acc=1.07, omega=omega)

mask = t > 400

ax.plot(np.mod(t[mask], 2 * np.pi / omega), theta[mask],
                    theta_dot[mask])

ax.set_xlabel(u'$t$', fontsize=26)
ax.set_ylabel(u'$\\theta$', fontsize=26)
ax.set_zlabel(u'$\dot{\\theta}$', fontsize=26)

plt.show()
예제 #7
0
import matplotlib.pyplot as plt
from scipy import fftpack
from scipy import signal

from dyna import forced_pendulum

omega = 2./3

dt = 2*np.pi / omega / 100

tf = 1000

acc_factors = [1, 1.07]


t, theta_0, theta_dot_0 = forced_pendulum(tf, dt, np.pi/3, 0,
                        q=0.5, acc=acc_factors[0], omega=omega)

t, theta_1, theta_dot_1 = forced_pendulum(tf, dt, np.pi/3, 0,
                        q=0.5, acc=acc_factors[1], omega=omega)

time_mask = t > 400

theta_0 = theta_0[time_mask]
theta_1 = theta_1[time_mask]

theta_0 -= theta_0.mean()
theta_1 -= theta_1.mean()

hann = signal.hanning(len(theta_0))
theta_0 *= hann
theta_1 *= hann