pykoop.dynamic_models.MassSpringDamper
- class MassSpringDamper(mass, stiffness, damping)
Bases:
ContinuousDynamicModel
Mass-spring-damper model.
State is
[position, velocity]
.Examples
Simulate a mass-spring-damper
>>> msd = pykoop.dynamic_models.MassSpringDamper(0.5, 0.7, 0.6) >>> x0 = np.array([1, 0]) >>> t, x = msd.simulate((0, 1), 1e-3, x0, lambda t: 0)
- __init__(mass, stiffness, damping)
Instantiate
MassSpringDamper
.
Methods
__init__
(mass, stiffness, damping)Instantiate
MassSpringDamper
.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.
Attributes
Compute
A
matrix.Compute
B
matrix.- 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]
- property A
Compute
A
matrix.
- property B
Compute
B
matrix.