Single Van der Pol oscillator

A well-known dynamical system is the Van der Pol oscillator, which is described by a second-order differential equation:

Van der Pol 2nd order differential equation

Rewriting it to a system of ordinary differential equations yields:

Van der Pol ODE1

Van der Pol ODE1

Van der Pol ODE2

In dynode, a Van der Pol system may be modelled as:

from dynode import SystemInterface

class VanDerPol(SystemInterface):

    def __init__(self):
        super().__init__()

        self.inputs.mu = 1.0

        self.states.x = 0.0
        self.ders.dx = 0.0

        self.states.y = 0.0
        self.ders.dy = 0.0

    def do_step(self, time):
        mu = self.inputs.mu
        x = self.states.x
        y = self.states.y

        self.ders.dx = y
        self.ders.dy = mu*(1-x**2)*y - x

And may be simulated like this:

from dynode.simulation import Simulation, Recorder

sys = VanDerPol()

rec = Recorder()
rec.store(sys, 'states.x', alias='x')
rec.store(sys, 'states.y', alias='y')

sim = Simulation()
sim.add_system(sys)
sim.add_observer(rec)

sys.states.x = 1
sim.simulate(100, 0.1)

import matplotlib.pyplot as plt
plt.plot(rec[sys]['time'], rec[sys]['x'])
plt.plot(rec[sys]['time'], rec[sys]['y'])
plt.show()