direct_data_driven_mpc.utilities.models.nonlinear_model

direct_data_driven_mpc.utilities.models.nonlinear_model#

Classes for modeling nonlinear systems.

This module provides a class for representing and simulating discrete-time nonlinear systems using a state-space representation.

Classes

NonlinearSystem

A class representing a nonlinear dynamical system.

class NonlinearSystem[source]#

A class representing a nonlinear dynamical system.

The system is defined by its dynamics and output functions, in the form:

\[ \begin{align}\begin{aligned}x(k+1) = f(x(k), u(k)) = f_0(x(k)) + B * u(k)\\y(k) = h(x(k), u(k)) = h_0(x(k)) + D * u(k)\end{aligned}\end{align} \]
Attributes:
  • f (Callable[[np.ndarray, np.ndarray], np.ndarray]) – The function representing the system’s dynamics.

  • h (Callable[[np.ndarray, np.ndarray], np.ndarray]) – The function representing the system’s output.

  • n (int) – The number of system states.

  • m (int) – The number of inputs to the system.

  • p (int) – The number of outputs of the system.

  • eps_max (float) – The upper bound of the system measurement noise.

  • x (numpy.ndarray) – The internal state vector of the system.

__init__(f: Callable[[ndarray, ndarray], ndarray], h: Callable[[ndarray, ndarray], ndarray], n: int, m: int, p: int, eps_max: float = 0.0)[source]#

Initialize a nonlinear dynamical system with a dynamics function f and an output function h.

Parameters:
  • f (Callable[[np.ndarray, np.ndarray], np.ndarray]) – The function representing the system’s dynamics.

  • h (Callable[[np.ndarray, np.ndarray], np.ndarray]) – The function representing the system’s output.

  • n (int) – The number of system states.

  • m (int) – The number of inputs to the system.

  • p (int) – The number of outputs of the system.

  • eps_max (float) – The upper bound of the system measurement noise. Defaults to 0.0.

simulate_step(u: ndarray, w: ndarray) ndarray[source]#

Simulate a single time step of the nonlinear system with a given input u.

The system simulation follows the state-space equations:

\[ \begin{align}\begin{aligned}x(k+1) = f(x(k), u(k)) = f_0(x(k)) + B * u(k)\\y(k) = h(x(k), u(k)) = h_0(x(k)) + D * u(k)\end{aligned}\end{align} \]
Parameters:
  • u (numpy.ndarray) – The input vector of shape (m,) at the current time step, where m is the number of inputs.

  • w (numpy.ndarray) – The measurement noise vector of shape (p,) at the current time step, where p is the number of outputs.

Returns:

np.ndarray – The output vector y of shape (p,) at the current time step, where p is the number of outputs.

Note

This method updates the x attribute, which represents the internal state vector of the system, after simulation.

simulate(U: ndarray, W: ndarray, steps: int) ndarray[source]#

Simulate the nonlinear system over multiple time steps.

Parameters:
  • U (numpy.ndarray) – An input matrix of shape (steps, m) where steps is the number of time steps and m is the number of inputs.

  • W (numpy.ndarray) – A noise matrix of shape (steps, p) where steps is the number of time steps and p is the number of outputs.

  • steps (int) – The number of simulation steps.

Returns:

np.ndarray – The output matrix Y of shape (steps, p) containing the simulated system outputs at each time step.

Note

This method updates the x attribute, which represents the internal state vector of the system, after each simulation step.