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, default100) – Number of time steps to simulate.dt (
float, default0.01) – Time step size for numerical integration.alpha (
float, default0.5) – Linear stiffness coefficient.beta (
float, default0.0625) – Nonlinear stiffness coefficient (cubic term).gamma (
float, default0.1) – Amplitude of the driving force.delta (
float, default2.5) – Damping coefficient.omega (
float, default2.0) – Angular frequency of the driving force.
- Returns:
df – Trajectory of the oscillator with columns
['position', 'velocity']andn_steps + 1samples. Has a MultiIndex with levels['step', 'time']. Metadata stored indf.attrsincludes:'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 ... )