def plot_underdamped_pendulum():
    pendulum = Oscillator(alpha=0.8, radius=1)
    time_steps = 400
    time_max = 10.0
    time = numpy.linspace(0, time_max, time_steps + 1)
    plt.axes(xlim=(0, 10), ylim=(-0.2, 0.2))
    trajectory = pendulum.get_trajectory(time_max, time_steps)
    theta = [position for position, velocity in trajectory]
    plt.plot(time, theta, "r")
def plot_theta_vs_theta_dash():
    pendulum = Oscillator(alpha=0.8, radius=1)
    time_steps = 400
    time_max = 10.0
    plt.axes(xlim=(-0.1, 0.1), ylim=(-0.25, 0.25))
    trajectory = pendulum.get_trajectory(time_max, time_steps)
    theta = [position for position, velocity in trajectory]
    theta_dash = [velocity for position, velocity in trajectory]
    plt.plot(theta, theta_dash, "b")
from matplotlib import animation
from matplotlib import pyplot as plt

from oscillator import Oscillator

fig = plt.figure()
ax = plt.axes(xlim=(-0.1, 0.1), ylim=(-0.2, 1))

pendulum_bob, = ax.plot([], [], lw=2, marker='o', color="r", markersize=30)
pendulum_rod, = ax.plot([], [], lw=2, color="black")

time_steps = 400
time_max = 10.0
pendulum = Oscillator()

trajectory = pendulum.get_trajectory(time_max, time_steps)
y = [position for position, velocity in trajectory]
x_coord = [math.sin(position) for position, velocity in trajectory]
y_coord = [(1 - math.cos(position)) for position, velocity in trajectory]


def init():
    pendulum_bob.set_data([], [])
    plt.title("Damped Pendulum Motion")
    plt.xlabel("X", fontsize=13, family='monospace')
    plt.ylabel("Y", fontsize=13, family='monospace')
    return pendulum_bob,


def animate(i):
    pendulum_bob.set_data(x_coord[i], y_coord[i])
Esempio n. 4
0
from matplotlib import pyplot as plt

from oscillator import Oscillator

fig = plt.figure()
ax = plt.axes(xlim=(0, 10), ylim=(-0.22, 0.22))

theta_line, = ax.plot([], [], lw=2, color="green")
theta_dash_line, = ax.plot([], [], lw=2, color="blue")

time_steps = 400
time_max = 10.0
osc = Oscillator()

x = np.linspace(0, time_max, time_steps + 1)
trajectory = osc.get_trajectory(time_max, time_steps)

y = [position for position, velocity in trajectory]
y_dash = [velocity for position, velocity in trajectory]


def init():
    theta_line.set_data([], [])
    plt.xlabel("Time", fontsize=13, family='monospace')
    plt.ylabel("Angular Displacement, Angular Velocity",
               fontsize=13,
               family='monospace')
    plt.title("Angular Displacement and Angular Velocity v/s Time",
              fontsize=13,
              family='monospace')
    blue_line = mlines.Line2D([], [],
Esempio n. 5
0
 def test_amplitude_decreases_when_friction_present(self):
     oscillator = Oscillator(alpha=1.0, radius=1.0)
     self.assertTrue(
         oscillator.state[0] > oscillator.get_trajectory(10.0, 500)[-1][0])
Esempio n. 6
0
 def test_state_unchanged_after_zero_time(self):
     oscillator = Oscillator()
     self.assertListEqual(oscillator.state,
                          list(oscillator.get_trajectory(0, 1)[0]))