control.nlsys
- control.nlsys(updfcn, outfcn=None, **kwargs)[source]
Create a nonlinear input/output system.
Creates an
InputOutputSystem
for a nonlinear system by specifying a state update function and an output function. The new system can be a continuous or discrete-time system.- Parameters
- updfcncallable (or
StateSpace
) Function returning the state update function
updfcn(t, x, u, params) -> array
where
x
is a 1-D array with shape (nstates,),u
is a 1-D array with shape (ninputs,),t
is a float representing the current time, andparams
is a dict containing the values of parameters used by the function.If a
StateSpace
system is passed as the update function, then a nonlinear I/O system is created that implements the linear dynamics of the state space system.- outfcncallable
Function returning the output at the given state
outfcn(t, x, u, params) -> array
where the arguments are the same as for
updfcn
.- inputsint, list of str or None, optional
Description of the system inputs. This can be given as an integer count or as a list of strings that name the individual signals. If an integer count is specified, the names of the signal will be of the form ‘s[i]’ (where ‘s’ is one of ‘u’, ‘y’, or ‘x’). If this parameter is not given or given as None, the relevant quantity will be determined when possible based on other information provided to functions using the system.
- outputsint, list of str or None, optional
Description of the system outputs. Same format as
inputs
.- statesint, list of str, or None, optional
Description of the system states. Same format as
inputs
.- dttimebase, optional
The timebase for the system, used to specify whether the system is operating in continuous or discrete time. It can have the following values:
dt
= 0: continuous-time system (default)dt
> 0: discrete-time system with sampling perioddt
dt
= True: discrete time with unspecified sampling perioddt
= None: no timebase specified
- namestring, optional
System name (used for specifying signals). If unspecified, a generic name ‘sys[id]’ is generated with a unique integer id.
- paramsdict, optional
Parameter values for the system. Passed to the evaluation functions for the system as default values, overriding internal defaults.
- updfcncallable (or
- Returns
- sys
NonlinearIOSystem
Nonlinear input/output system.
- sys
- Other Parameters
- input_prefix, output_prefix, state_prefixstring, optional
Set the prefix for input, output, and state signals. Defaults = ‘u’, ‘y’, ‘x’.
Examples
>>> def kincar_update(t, x, u, params): ... l = params['l'] # wheelbase ... return np.array([ ... np.cos(x[2]) * u[0], # x velocity ... np.sin(x[2]) * u[0], # y velocity ... np.tan(u[1]) * u[0] / l # angular velocity ... ]) >>> >>> def kincar_output(t, x, u, params): ... return x[0:2] # x, y position >>> >>> kincar = ct.nlsys( ... kincar_update, kincar_output, states=3, inputs=2, outputs=2, ... params={'l': 1}) >>> >>> timepts = np.linspace(0, 10) >>> response = ct.input_output_response( ... kincar, timepts, [10, 0.05 * np.sin(timepts)])