Note
Click here to download the full example code
The Van der Pol Oscillator¶
Here, we will introduce the Van der Pol model, a widely studied non-linear oscillator model [1]. In its two-dimensional form, the Van der Pol oscillator is governed by the following non-linear ODEs:
with damping constant . Depending on the latter parameter, the periodic solutions of the Van der Pol oscillator change,
with simple harmonic oscillations for
and non-harmonic limit cycle oscillations for
.
In this gallery, we will simulate and visualize the model dynamics for
and
.
Van der Pol oscillator dynamics¶
First, we will load a CircuitTemplate
instance via the path to the model definition.
We will the use the CircuitTemplate.run
method to solve the initial value problem of the above defined
differential equations for a time interval from 0 to the given simulation time.
This solution will be calculated numerically by a differential equation solver in the backend, starting with a
defined step-size. Here, we use the default backend and a Runge-Kutta 2(3) solver.
Check out the arguments of the code:CircuitTemplate.run() method for a detailed explanation of the
arguments that you can use to adjust this numerical procedure.
from pyrates import CircuitTemplate, clear
# define simulation time and input start and stop
T = 100.0
step_size = 1e-2
# load model template
model = CircuitTemplate.from_yaml("model_templates.oscillators.vanderpol.vdp")
# set mu to 0
model.update_var({'p/vdp_op/mu': 0.0})
results = model.run(step_size=step_size, simulation_time=T, outputs={'x': 'p/vdp_op/x'}, solver='scipy', method='RK23')
# plot resulting phases
import matplotlib.pyplot as plt
plt.plot(results)
plt.show()
# clear results
clear(model)
As expected, we found harmonical oscillations for .
Now, we will repeat the procedure for
.
# load model template
model = CircuitTemplate.from_yaml("model_templates.oscillators.vanderpol.vdp")
# set mu to 0
model.update_var({'p/vdp_op/mu': 5.0})
results = model.run(step_size=step_size, simulation_time=T, outputs={'x': 'p/vdp_op/x'}, solver='scipy', method='RK23')
# plot resulting phases
plt.plot(results)
plt.show()
We find a much less harmonical waveform of the oscillations. For investigations of the Van der Pol oscillator driven by a periodic input signal, see the entrainment example in the gallery section Model analysis.
Total running time of the script: ( 0 minutes 0.000 seconds)