pykoop.dynamic_models.Pendulum
- class Pendulum(mass, length, damping=0)
Bases:
ContinuousDynamicModel
Point-mass pendulum with optional damping.
State is
[angle, angular_velocity]
.Examples
Simulate a pendulum
>>> pend = pykoop.dynamic_models.Pendulum(0.5, 1, 0.6) >>> x0 = np.array([np.pi / 2, 0]) >>> t, x = pend.simulate((0, 1), 1e-3, x0, lambda t: 0)
Methods
__init__
(mass, length[, damping])Instantiate
Pendulum
.f
(t, x, u)Implement differential equation.
g
(t, x)Implement output equation.
simulate
(t_range, t_step, x0, u, **kwargs)Simulate the model using numerical integration.
- f(t, x, u)
Implement differential equation.
- Parameters:
t (float) – Time (s).
x (np.ndarray) – State.
u (np.ndarray) – Input.
- Returns:
Time derivative of state.
- Return type:
np.ndarray
- g(t, x)
Implement output equation.
- Parameters:
t (float) – Time (s).
x (np.ndarray) – State.
- Returns:
Measurement of state.
- Return type:
np.ndarray
- simulate(t_range, t_step, x0, u, **kwargs)
Simulate the model using numerical integration.
- Parameters:
- Returns:
Time and state at every timestep. Each timestep is one row.
- Return type:
Tuple[np.ndarray, np.ndarray]