systems module

class simupy.systems.DynamicalSystem(state_equation_function=None, output_equation_function=None, event_equation_function=None, update_equation_function=None, dim_state=0, dim_input=0, dim_output=0, dt=0, initial_condition=None)[source]

Bases: object

A dynamical system which models systems of the form:

xdot(t) = state_equation_function(t,x,u)
y(t) = output_equation_function(t,x)

or:

y(t) = output_equation_function(t,u)

These could also represent discrete-time systems, in which case xdot(t) represents x[k+1].

This can also model discontinuous systems. Discontinuities must occur on zero-crossings of the event_equation_function, which take the same arguments as output_equation_function, depending on dim_state. At the zero-crossing, update_equation_function is called with the same arguments. If dim_state > 0, the return value of update_equation_function is used as the state of the system immediately after the discontinuity.

Parameters:
  • state_equation_function (callable, optional) – The derivative (or update equation) of the system state. Not needed if dim_state is zero.
  • output_equation_function (callable, optional) – The output equation of the system. A system must have an output_equation_function. If not set, uses full state output.
  • event_equation_function (callable, optional) – The function whose output determines when discontinuities occur.
  • update_equation_function (callable, optional) – The function called when a discontinuity occurs.
  • dim_state (int, optional) – Dimension of the system state. Optional, defaults to 0.
  • dim_input (int, optional) – Dimension of the system input. Optional, defaults to 0.
  • dim_output (int, optional) – Dimension of the system output. Optional, defaults to dim_state.
  • dt (float, optional) – Sample rate of the system. Optional, defaults to 0 representing a continuous time system.
  • initial_condition (array_like of numerical values, optional) – Array or Matrix used as the initial condition of the system. Defaults to zeros of the same dimension as the state.
initial_condition
prepare_to_integrate()[source]
validate()[source]
class simupy.systems.LTISystem(*args, initial_condition=None, dt=0)[source]

Bases: simupy.systems.DynamicalSystem

A linear, time-invariant system.

Construct an LTI system with the following input formats:

  1. state matrix A, input matrix B, output matrix C for systems with state:

    dx_dt = Ax + Bu
    y = Hx
    
  2. state matrix A, input matrix B for systems with state, assume full state output:

    dx_dt = Ax + Bu
    y = Ix
    
  3. gain matrix K for systems without state:

    y = Kx
    

The matrices should be numeric arrays of consistent shape. The class provides A, B, C and F, G, H aliases for the matrices of systems with state, as well as a K alias for the gain matrix. The data alias provides the matrices as a tuple.

A
B
C
F
G
H
K
data
validate()[source]
class simupy.systems.SwitchedSystem(state_equations_functions=None, output_equations_functions=None, event_variable_equation_function=None, event_bounds=None, state_update_equation_function=None, dim_state=0, dim_input=0, dim_output=0, dt=0, initial_condition=None)[source]

Bases: simupy.systems.DynamicalSystem

Provides a useful pattern for discontinuous systems where the state and output equations change depending on the value of a function of the state and/or input (event_variable_equation_function). Most of the usefulness comes from constructing the event_equation_function with a Bernstein basis polynomial with roots at the boundaries. This class also provides logic for outputting the correct state and output equation based on the event_variable_equation_function value.

Parameters:
  • state_equations_functions (array_like of callables, optional) – The derivative (or update equation) of the system state. Not needed if dim_state is zero. The array indexes the event-state and should be one more than the number of event bounds. This should also be indexed to match the boundaries (i.e., the first function is used when the event variable is below the first event_bounds value). If only one callable is provided, the callable is used in each condition.
  • output_equations_functions (array_like of callables, optional) – The output equation of the system. A system must have an output_equation_function. If not set, uses full state output. The array indexes the event-state and should be one more than the number of event bounds. This should also be indexed to match the boundaries (i.e., the first function is used when the event variable is below the first event_bounds value). If only one callable is provided, the callable is used in each condition.
  • event_variable_equation_function (callable) – When the output of this function crosses the values in event_bounds, a discontuity event occurs.
  • event_bounds (array_like of floats) – Defines the boundary points the trigger discontinuity events based on the output of event_variable_equation_function.
  • state_update_equation_function (callable, optional) – When an event occurs, the state update equation function is called to determine the state update. If not set, uses full state output, so the state is not changed upon a zero-crossing of the event variable function.
  • dim_state (int, optional) – Dimension of the system state. Optional, defaults to 0.
  • dim_input (int, optional) – Dimension of the system input. Optional, defaults to 0.
  • dim_output (int, optional) – Dimension of the system output. Optional, defaults to dim_state.
  • dt (float, optional) – Sample rate of the system. Optional, defaults to 0 representing a continuous time system.
event_bounds
event_equation_function(*args)[source]
output_equation_function(*args)[source]
prepare_to_integrate()[source]
state_equation_function(*args)[source]
update_equation_function(*args)[source]
validate()[source]
simupy.systems.SystemFromCallable(incallable, dim_input, dim_output, dt=0)[source]

Construct a memoryless system from a callable.

Parameters:
  • incallable (callable) – Function to use as the output_equation_function. Should have signature (t, u) if dim_input > 0 or (t) if dim_input = 0.
  • dim_input (int) – Dimension of input.
  • dim_output (int) – Dimension of output.
simupy.systems.full_state_output(*args)[source]

A drop-in output_equation_function for stateful systems that provide output the full state directly.