Pendulum¤
Main module for a pendulum.
Pendulum
¤
Generate time series data for a pendulum.
We describe a generic pendulum system by the Lagrangian action $$ S_L[\theta] = I \int_{t_0}^{t_1} \mathbb{d}t \left\{\frac{1}{2} \dot\theta^2 + \omega_0^2 \cos\theta \right\}\,, $$ where \(\theta\) is the angle from the vertical to the pendulum; \(I\) is the inertia parameter introduced for dimensional reasons, and \(\omega_0\) the frequency parameter.
Details are collected in the tutorial.
Source code in hamilflow/models/pendulum.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
|
definition: dict[str, dict[str, Any]]
cached
property
¤
Model params and initial conditions defined as a dictionary.
freq: float
cached
property
¤
Frequency.
Returns:
Type | Description |
---|---|
float
|
\(\frac{\pi}{2K(k^2)}\omega_0\), where \(K(m)\) is Legendre's complete elliptic integral of the first kind |
omega0: float
property
¤
Original angular frequency of the system.
period: float
cached
property
¤
Period.
Returns:
Type | Description |
---|---|
float
|
\(\frac{4K(k^2)}{\omega_0}\), where \(K(m)\) is Legendre's complete elliptic integral of the first kind |
__call__(t)
¤
Generate the variables of the pendulum in time together with the time steps.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
t |
TypeTime
|
time steps |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
values of the variables angle |
Source code in hamilflow/models/pendulum.py
153 154 155 156 157 158 159 160 161 162 163 |
|
generate_from(n_periods, n_samples_per_period)
¤
Generate the time sequence from more interpretable params.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n_periods |
int
|
number of periods to include |
required |
n_samples_per_period |
int
|
number of samples in each period |
required |
Returns:
Type | Description |
---|---|
DataFrame
|
an array that contains all the timesteps |
Source code in hamilflow/models/pendulum.py
141 142 143 144 145 146 147 148 149 150 151 |
|
theta(t)
¤
Angle \(\theta\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
t |
Sequence[float] | ArrayLike
|
time |
required |
Returns:
Type | Description |
---|---|
NDArray[float64]
|
\(\theta(t) = 2\arcsin\!\big(k\cdot\mathrm{cd}(\omega_0 t, k^2)\big)\), where \(\mathrm{cd}(z, k)\) is a Jacobian elliptic function |
Source code in hamilflow/models/pendulum.py
130 131 132 133 134 135 136 137 138 139 |
|
u(t)
¤
Give the convenient generalised coordinate \(u\), \(\sin u \coloneqq \frac{\sin\frac{\theta}{2}}{\sin\frac{\theta_0}{2}}\).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
t |
Sequence[float] | ArrayLike
|
time |
required |
Returns:
Type | Description |
---|---|
NDArray[float64]
|
\(u(t) = \mathrm{am}\!\big(\omega_0 t + K(k^2), k^2\big)\), where \(\mathrm{am}(x, k)\) is Jacobi's amplitude function, \(K(m)\) is Legendre's complete elliptic integral of the first kind |
Source code in hamilflow/models/pendulum.py
118 119 120 121 122 123 124 125 126 127 128 |
|
PendulumIC
¤
Bases: BaseModel
The initial condition for a pendulum.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
theta0 |
\(-\frac{\pi}{2} \le \theta_0 \le \frac{\pi}{2}\), the initial angle |
required |
Source code in hamilflow/models/pendulum.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
|
k: float
cached
property
¤
A convenient number for elliptic functions.
Returns:
Type | Description |
---|---|
float
|
\(\sin\frac{\theta_0}{2}\) |
PendulumSystem
¤
Bases: BaseModel
The params for the pendulum.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
omega0 |
\(\omega_0 \coloneqq \sqrt{\frac{U}{I}} > 0\), frequency parameter |
required |
Source code in hamilflow/models/pendulum.py
17 18 19 20 21 22 23 24 |
|