Van der Pol
The Van der Pol oscillator x'' = μ (1 - x²) x' - x.
- Class:
VanDerPolSystem - Import:
from skcomplex.systems.physics.nonlinear_oscillators import VanDerPolSystem - Field:
physics/nonlinear_oscillators - Topics:
limit cycle,ode,second order,oscillation - References:
- van der Pol 1926
- Gros 2015
Use this system
The block imports the class and simulates the system with its default parameters and its tuned run settings.
from skcomplex.systems.physics.nonlinear_oscillators import VanDerPolSystem
trajectory = VanDerPolSystem().prepare().simulate()
Parameters
The model parameters take these defaults, and set_params changes them.
| Parameter | Default |
|---|---|
x |
2.0 |
v |
0.0 |
mu |
1.0 |
solver |
'auto' |
backend |
'auto' |
Tags
The system with its default parameters has these capability tags, which solvers and analyses check.
| Tag | Values |
|---|---|
| Time | continuous |
| Space | none |
| Laws | rate |
| Randomness | deterministic |
| Domains | real |
| Structure | fixed |
Class
The source of the class shows how it builds its components from its model parameters.
class VanDerPolSystem(BaseSystem):
"""The Van der Pol oscillator `x'' = μ (1 - x²) x' - x`.
The oscillator settles on a limit cycle for `μ > 0`.
The system has the displacement `oscillator.x` and its velocity `oscillator.x'`.
Args:
x:
The initial displacement.
v:
The initial velocity.
mu:
The strength of the nonlinear damping.
label:
The label of the system, which names it when it is nested in another one.
solver:
The solver of the problem, or `'auto'` for the one the system chooses.
backend:
The backend that evaluates the compiled functions, or `'auto'` for the one the system chooses.
Examples:
>>> from skcomplex.systems.physics.nonlinear_oscillators import VanDerPolSystem
>>> VanDerPolSystem(mu=3.0).prepare().system_.interactions[0].mu
3.0
"""
field = 'physics/nonlinear_oscillators'
topics = ('limit cycle', 'ode', 'second order', 'oscillation')
references = ('van der Pol 1926', 'Gros 2015')
until = 50.0
dt = 0.05
def __init__(
self,
x: float = 2.0,
v: float = 0.0,
*,
mu: float = 1.0,
label: str = 'system',
solver: BaseSolver | str = 'auto',
backend: BaseBackend | str = 'auto',
) -> None:
super().__init__(label, solver=solver, backend=backend)
self.x = x
self.v = v
self.mu = mu
def _prepare(self, context: Sequence[Observable] | None = None) -> None:
"""Set the system of the Van der Pol oscillator, a forced one without a force.
Args:
context:
The observables to compile with the problem, or `None` for none.
"""
super()._prepare(context)
oscillator = VanDerPolElement('oscillator', x=self.x, values={"x'": self.v})
damping = ForcedVanDerPolInteraction('damping', target='oscillator', mu=self.mu, A=0.0)
self.system_ = System(self.label, elements=[oscillator], interactions=[damping])
Components
The system uses these element and interaction classes, each with its nearest class of the core.
Elements:
VanDerPolElement, fromElement
Interactions:
ForcedVanDerPolInteraction, fromInteraction
class VanDerPolElement(Element):
"""Van der Pol oscillator at the displacement `x`, with the velocity `x'`.
`ForcedVanDerPolInteraction` moves it by `x'' = mu (1 - x^2) x' - x + A cos(omega t)`. The damping is negative for
small amplitudes and positive for large ones, so the unforced oscillator, `A = 0`, settles on a limit cycle of
amplitude near 2.
Args:
label:
The label of the oscillator.
x:
The initial displacement.
values:
Further values by name, such as an initial velocity named with a prime, or `None`.
Examples:
>>> from skcomplex.core.systems import System
>>> from skcomplex.systems.physics.nonlinear_oscillators import ForcedVanDerPolInteraction, VanDerPolElement
>>> damping = ForcedVanDerPolInteraction('damping', target='oscillator', A=0.0)
>>> system = System(elements=[VanDerPolElement('oscillator', x=0.1)], interactions=[damping]).prepare()
>>> trajectory = system.simulate(until=50.0, dt=0.1)
>>> round(float(abs(trajectory.get_values('oscillator.x')[-300:]).max()), 1)
2.0
"""
def __init__(
self,
label: str,
*,
x: float = 2.0,
values: Mapping[str, object] | None = None,
) -> None:
super().__init__(label, values=values)
self.x = x
class ForcedVanDerPolInteraction(Interaction):
"""Van der Pol dynamics `x'' = mu (1 - x²) x' - x + A cos(omega t)` of an oscillator driven by a periodic force.
Args:
label:
The label of the interaction.
target:
The path of the oscillator.
mu:
The strength of the nonlinear damping.
A:
The amplitude of the force.
omega:
The angular frequency of the force.
Examples:
>>> from skcomplex.systems.physics.nonlinear_oscillators import ForcedVanDerPolInteraction
>>> ForcedVanDerPolInteraction('drive', target='oscillator', A=0.5).A
0.5
"""
law_classes = (RateLaw,)
def __init__(
self,
label: str,
*,
target: Role,
mu: Annotated[float, RealSet.closed_open(0, oo)] = 1.0,
A: float = 1.0,
omega: float = 1.0,
) -> None:
super().__init__(label)
self.target = target
self.mu = mu
self.A = A
self.omega = omega
def _prepare(self, context: SimpleNamespace) -> None:
"""Set the acceleration of the oscillator.
Args:
context:
The namespace of the oscillator, the time `t`, and the parameters.
"""
super()._prepare(context)
x, t = context.target.x, context.t
damping = context.mu * (1 - x**2) * x.diff(t)
self.laws_ = [RateLaw(x.diff(t, 2), damping - x + context.A * cos(context.omega * t))]
Equations
The equations are those that symbolic returns for the system with its default parameters.
oscillator.x: diff(x_oscillator(t), t, t) == -(x_oscillator(t)^2 - 1)*mu_damping*diff(x_oscillator(t), t) + A_damping*cos(omega_damping*t) - x_oscillator(t)