make_duffing

kooplearn.datasets.make_duffing(X0, n_steps=100, dt=0.01, alpha=0.5, beta=0.0625, gamma=0.1, delta=2.5, omega=2.0)[source]

Generate a trajectory from the Duffing oscillator.

The Duffing oscillator is a damped driven nonlinear harmonic oscillator commonly used to study chaotic dynamics in physics and engineering.

The system is governed by the differential equation:

\[x'' + \delta x' + \alpha x + \beta x^3 = \gamma \text{cos}(\omega t).\]
Parameters:
  • X0 (array-like, shape (2,)) – Initial conditions [position, velocity].

  • n_steps (int, default 100) – Number of time steps to simulate.

  • dt (float, default 0.01) – Time step size for numerical integration.

  • alpha (float, default 0.5) – Linear stiffness coefficient.

  • beta (float, default 0.0625) – Nonlinear stiffness coefficient (cubic term).

  • gamma (float, default 0.1) – Amplitude of the driving force.

  • delta (float, default 2.5) – Damping coefficient.

  • omega (float, default 2.0) – Angular frequency of the driving force.

Returns:

df – Trajectory of the oscillator with columns ['position', 'velocity'] and n_steps + 1 samples. Has a MultiIndex with levels ['step', 'time']. Metadata stored in df.attrs includes:

  • 'generator': 'make_duffing';

  • 'X0': initial conditions;

  • 'params': dict of all parameters.

Return type:

pandas.DataFrame

Examples

>>> import numpy as np
>>> X0 = np.array([0.0, 0.0])
>>> df = make_duffing(X0, n_steps=1000, dt=0.01)
>>> df.shape
(1001, 2)
>>> df.columns.tolist()
['position', 'velocity']
>>> df.attrs['generator']
'make_duffing'
>>> # Access time values from index
>>> times = df.index.get_level_values('time')
>>> # Generate chaotic trajectory
>>> df_chaotic = make_duffing(
...     X0=[0.1, 0.1],
...     n_steps=5000,
...     alpha=-1.0,
...     beta=1.0,
...     gamma=0.3,
...     delta=0.25,
...     omega=1.0
... )