ss
State-space model
Description
Usess
to create real-valued or complex-valued state-space models, or to convertdynamic system modelsto state-space model form. You can also usess
to create generalized state-space (genss
) models or uncertain state-space (uss
(Robust Control Toolbox)) models.
A state-space model is a mathematical representation of a physical system as a set of input, output, and state variables related by first-order differential equations. The state variables define the values of the output variables. Thess
model object can represent SISO or MIMO state-space models in continuous time or discrete time.
In continuous-time, a state-space model is of the following form:
Here,x
,u
和y
represent the states, inputs and outputs respectively, whileA
,B
,C
和D
are the state-space matrices. Thess
object represents a state-space model in MATLAB®storingA
,B
,C
和D
along with other information such as sample time, names and delays specific to the inputs and outputs.
You can create a state-space model object by either specifying the state, input and output matrices directly, or by converting a model of another type (such as a transfer function modeltf
) to state-space form. For more information, seeState-Space Models. You can use anss
model object to:
Perform linear analysis
Represent a linear time-invariant (LTI) model to perform control design
Combine with other LTI models to represent a more complex system
Creation
Syntax
Description
creates a continuous-time state-space model object of the following form:sys
= ss(A
,B
,C
,D
)
For instance, consider a plant withNx
states,Ny
outputs, andNu
inputs. The state-space matrices are:
A
is anNx
-by-Nx
real- or complex-valued matrix.B
is anNx
-by-Nu
real- or complex-valued matrix.C
is anNy
-by-Nx
real- or complex-valued matrix.D
is anNy
-by-Nu
real- or complex-valued matrix.
converts tosys
= ss(ltiSys
,component
)ss
object form the measured component, the noise component or both of specifiedcomponent
of an identified linear time-invariant (LTI) modelltiSys
. Use this syntax only whenltiSys
is an identified (LTI) model such as anidtf
(System Identification Toolbox),idss
(System Identification Toolbox),idproc
(System Identification Toolbox),idpoly
(System Identification Toolbox)oridgrey
(System Identification Toolbox)object.
returns the minimal state-space realization with no uncontrollable or unobservable states. This realization is equivalent tosys
= ss(ssSys
,'minimal')minreal(ss(sys))
where matrixA
has the smallest possible dimension.
Conversion to state-space form is not uniquely defined in the SISO case. It is also not guaranteed to produce a minimal realization in the MIMO case. For more information, seeRecommended Working Representation.
returns an explicit state-space realization(E = I)of the dynamic system state-space modelsys
= ss(ssSys
,'explicit')ssSys
.ss
returns an error ifssSys
is improper. For more information on explicit state-space realization, seeState-Space Models.
Input Arguments
A
—State matrix
Nx
-by-Nx
matrix
State matrix, specified as anNx
-by-Nx
matrix where,Nx
is the number of states. This input sets the value of propertyA.
B
—Input-to-state matrix
Nx
-by-Nu
matrix
Input-to-state matrix, specified as anNx
-by-Nu
matrix where,Nx
is the number of states andNu
is the number of inputs. This input sets the value of propertyB.
C
—State-to-output matrix
Ny
-by-Nx
matrix
State-to-output matrix, specified as anNy
-by-Nx
matrix where,Nx
is the number of states andNy
is the number of outputs. This input sets the value of propertyC.
D
—Feedthrough matrix
Ny
-by-Nu
matrix
Feedthrough matrix, specified as anNy
-by-Nu
matrix where,Ny
is the number of outputs andNu
is the number of inputs. This input sets the value of propertyD.
ts
—Sample time
scalar
Sample time, specified as a scalar. For more information, seeTsproperty.
ltiSys
—Dynamic system to convert to state-space form
dynamic system model|model array
Dynamic system to convert to state-space form, specified as a SISO or MIMOdynamic system modelor array of dynamic system models. Dynamic systems that you can convert include:
Continuous-time or discrete-time numeric LTI models, such as
tf
,zpk
,ss
, orpid
models.Generalized or uncertain LTI models such as
genss
oruss
(Robust Control Toolbox)models. (Using uncertain models requires Robust Control Toolbox™ software.)The resulting state-space model assumes
current values of the tunable components for tunable control design blocks.
nominal model values for uncertain control design blocks.
Identified LTI models, such as
idtf
(System Identification Toolbox),idss
(System Identification Toolbox),idproc
(System Identification Toolbox),idpoly
(System Identification Toolbox), andidgrey
(System Identification Toolbox)models. To select the component of the identified model to convert, specifycomponent
. If you do not specifycomponent
,ss
converts the measured component of the identified model by default.(Using identified models requires System Identification Toolbox™ software.)
component
—Component of identified model
'measured'
(default) |'noise'
|'augmented'
Component of identified model to convert, specified as one of the following:
'measured'
— Convert the measured component ofsys
.'noise'
— Convert the noise component ofsys
'augmented'
— Convert both the measured and noise components ofsys
.
component
only applies whensys
is an identified LTI model.
For more information on identified LTI models and their measured and noise components, seeIdentified LTI Models.
ssSys
—Dynamic system model to convert to minimal realization or explicit form
ss
model object
Dynamic system model to convert to minimal realization or explicit form, specified as anss
model object.
Output Arguments
sys
— Output system model
ss
model object |genss
model object |uss
model object
Output system model, returned as:
A state-space (
ss
) model object, when the inputsA
,B
,C
和D
are numeric matrices or when converting from another model object type.A generalized state-space model (
genss
) object, when one or more of the matricesA
,B
,C
和D
includes tunable parameters, such asrealp
parameters or generalized matrices (genmat
). For an example, seeCreate State-Space Model with Both Fixed and Tunable Parameters.An uncertain state-space model (
uss
) object, when one or more of the inputsA
,B
,C
和D
includes uncertain matrices. Using uncertain models requires Robust Control Toolbox software.
Properties
A
—State matrix
Nx
-by-Nx
matrix
State matrix, specified as anNx
-by-Nx
matrix whereNx
is the number of states. The state-matrix can be represented in many ways depending on the desired state-space model realization such as:
Model Canonical Form
Companion Canonical Form
Observable Canonical Form
Controllable Canonical Form
For more information, seeState-Space Realizations.
B
—Input-to-state matrix
Nx
-by-Nu
matrix
Input-to-state matrix, specified as anNx
-by-Nu
matrix whereNx
is the number of states andNu
is the number of inputs.
C
—State-to-output matrix
Ny
-by-Nx
matrix
State-to-output matrix, specified as anNy
-by-Nx
matrix whereNx
is the number of states andNy
is the number of outputs.
D
—Feedthrough matrix
Ny
-by-Nu
matrix
Feedthrough matrix, specified as anNy
-by-Nu
matrix whereNy
is the number of outputs andNu
is the number of inputs.D
is also called as the static gain matrix which represents the ratio of the output to the input under steady state condition.
E
—Matrix for implicit state-space models
[](default) |Nx
-by-Nx
matrix
Matrix for implicit or descriptor state-space models, specified as aNx
-by-Nx
matrix.E
is empty by default, meaning that the state equation is explicit. To specify an implicit state equationEdx/dt=Ax+Bu, set this property to a square matrix of the same size asA
. Seedss
for more information about creating descriptor state-space models.
Scaled
—Logical value indicating whether scaling is enabled or disabled
0
(default) |1
Logical value indicating whether scaling is enabled or disabled, specified as either0
or1
.
WhenScaled
is set to0
(disabled), then most numerical algorithms acting on the state-space modelsys
automatically rescale the state vector to improve numerical accuracy. You can prevent such auto-scaling by settingScaled
to1
(enabled).
For more information about scaling, seeprescale
.
StateName
—State names
''
(default) |character vector|cell array of character vectors
State names, specified as one of the following:
Character vector — For first-order models, for example,
'velocity'
Cell array of character vectors — For models with two or more states
StateName
is empty''
for all states by default.
StatePath
—State path
''
(default) |character vector|cell array of character vectors
State path to facilitate state block path management in linearization, specified as one of the following:
Character vector — For first-order models
Cell array of character vectors — For models with two or more states
StatePath
is empty''
for all states by default.
StateUnit
—State units
''
(default) |character vector|cell array of character vectors
State units, specified as one of the following:
Character vector — For first-order models, for example,
'm/s'
Cell array of character vectors — For models with two or more states
UseStateUnit
to keep track of the units of each state.StateUnit
has no effect on system behavior.StateUnit
is empty''
for all states by default.
InternalDelay
—Internal delays in the model
vector
Internal delays in the model, specified as a vector. Internal delays arise, for example, when closing feedback loops on systems with delays, or when connecting delayed systems in series or parallel. For more information about internal delays, seeClosing Feedback Loops with Time Delays.
For continuous-time models, internal delays are expressed in the time unit specified by theTimeUnit
property of the model. For discrete-time models, internal delays are expressed as integer multiples of the sample timeTs
. For example,InternalDelay = 3
means a delay of three sampling periods.
You can modify the values of internal delays using the propertyInternalDelay
. However, the number of entries insys.InternalDelay
cannot change, because it is a structural property of the model.
InputDelay
—Input delay
0
(default) |scalar|Nu
-by-1 vector
Input delay for each input channel, specified as one of the following:
Scalar — Specify the input delay for a SISO system or the same delay for all inputs of a multi-input system.
Nu
-by-1 vector — Specify separate input delays for input of a multi-input system, whereNu
is the number of inputs.
For continuous-time systems, specify input delays in the time unit specified by theTimeUnit
property. For discrete-time systems, specify input delays in integer multiples of the sample time,Ts
.
For more information, seeTime Delays in Linear Systems.
OutputDelay
—Output delay
0
(default) |scalar|Ny
-by-1 vector
Output delay for each output channel, specified as one of the following:
Scalar — Specify the output delay for a SISO system or the same delay for all outputs of a multi-output system.
Ny
1向量-指定单独的输出延迟output of a multi-output system, whereNy
is the number of outputs.
For continuous-time systems, specify output delays in the time unit specified by theTimeUnit
property. For discrete-time systems, specify output delays in integer multiples of the sample time,Ts
.
For more information, seeTime Delays in Linear Systems.
Ts
—Sample time
0
(default) |positive scalar|-1
Sample time, specified as:
0
for continuous-time systems.A positive scalar representing the sampling period of a discrete-time system. Specify
Ts
in the time unit specified by theTimeUnit
property.-1
for a discrete-time system with an unspecified sample time.
TimeUnit
—Time variable units
'seconds'
(default) |'nanoseconds'
|'microseconds'
|'milliseconds'
|'minutes'
|'hours'
|'days'
|'weeks'
|'months'
|'years'
| ...
Time variable units, specified as one of the following:
'nanoseconds'
'microseconds'
'milliseconds'
'seconds'
'minutes'
'hours'
'days'
'weeks'
'months'
'years'
ChangingTimeUnit
has no effect on other properties, but changes the overall system behavior. UsechgTimeUnit
to convert between time units without modifying system behavior.
InputName
—Input channel names
''
(default) |character vector|cell array of character vectors
Input channel names, specified as one of the following:
A character vector, for single-input models.
一个细胞array of character vectors, for multi-input models.
''
, no names specified, for any input channels.
或者,您可以指定输入名称相乘i-input models using automatic vector expansion. For example, ifsys
is a two-input model, enter the following:
sys.InputName ='controls';
The input names automatically expand to{'controls(1)';'controls(2)'}
.
You can use the shorthand notationu
to refer to theInputName
property. For example,sys.u
相当于sys.InputName
.
UseInputName
to:
Identify channels on model display and plots.
Extract subsystems of MIMO systems.
Specify connection points when interconnecting models.
InputUnit
—Input channel units
''
(default) |character vector|cell array of character vectors
Input channel units, specified as one of the following:
A character vector, for single-input models.
一个细胞array of character vectors, for multi-input models.
''
, no units specified, for any input channels.
UseInputUnit
to specify input signal units.InputUnit
has no effect on system behavior.
InputGroup
—Input channel groups
structure
Input channel groups, specified as a structure. UseInputGroup
to assign the input channels of MIMO systems into groups and refer to each group by name. The field names ofInputGroup
are the group names and the field values are the input channels of each group. For example, enter the following to create input groups namedcontrols
和noise
that include input channels1
和2
, and3
和5
, respectively.
sys.InputGroup.controls = [1 2]; sys.InputGroup.noise = [3 5];
You can then extract the subsystem from thecontrols
inputs to all outputs using the following.
sys(:,'controls')
By default,InputGroup
is a structure with no fields.
OutputName
—Output channel names
''
(default) |character vector|cell array of character vectors
Output channel names, specified as one of the following:
A character vector, for single-output models.
一个细胞array of character vectors, for multi-output models.
''
, no names specified, for any output channels.
Alternatively, you can assign output names for multi-output models using automatic vector expansion. For example, ifsys
is a two-output model, enter the following.
sys.OutputName ='measurements';
The output names automatically expand to{'measurements(1)';'measurements(2)'}
.
You can also use the shorthand notationy
to refer to theOutputName
property. For example,sys.y
相当于sys.OutputName
.
UseOutputName
to:
Identify channels on model display and plots.
Extract subsystems of MIMO systems.
Specify connection points when interconnecting models.
OutputUnit
—Output channel units
''
(default) |character vector|cell array of character vectors
Output channel units, specified as one of the following:
A character vector, for single-output models.
一个细胞array of character vectors, for multi-output models.
''
, no units specified, for any output channels.
UseOutputUnit
to specify output signal units.OutputUnit
has no effect on system behavior.
OutputGroup
—Output channel groups
structure
Output channel groups, specified as a structure. UseOutputGroup
to assign the output channels of MIMO systems into groups and refer to each group by name. The field names ofOutputGroup
are the group names and the field values are the output channels of each group. For example, create output groups namedtemperature
和measurement
that include output channels1
, and3
和5
, respectively.
sys.OutputGroup.temperature = [1]; sys.OutputGroup.measurement = [3 5];
You can then extract the subsystem from all inputs to themeasurement
outputs using the following.
sys('measurement',:)
By default,OutputGroup
is a structure with no fields.
Name
—System name
''
(default) |character vector
System name, specified as a character vector. For example,'system_1'
.
Notes
—User-specified text
{}
(default) |character vector|cell array of character vectors
User-specified text that you want to associate with the system, specified as a character vector or cell array of character vectors. For example,'System is MIMO'
.
UserData
—User-specified data
[]
(default) |any MATLAB data type
User-specified data that you want to associate with the system, specified as any MATLAB data type.
SamplingGrid
—Sampling grid for model arrays
structure array
Sampling grid for model arrays, specified as a structure array.
UseSamplingGrid
to track the variable values associated with each model in a model array, including identified linear time-invariant (IDLTI) model arrays.
Set the field names of the structure to the names of the sampling variables. Set the field values to the sampled variable values associated with each model in the array. All sampling variables must be numeric scalars, and all arrays of sampled values must match the dimensions of the model array.
For example, you can create an 11-by-1 array of linear models,sysarr
, by taking snapshots of a linear time-varying system at timest = 0:10
. The following code stores the time samples with the linear models.
sysarr.SamplingGrid = struct('time',0:10)
Similarly, you can create a 6-by-9 model array,M
, by independently sampling two variables,zeta
和w
. The following code maps the(zeta,w)
values toM
.
[zeta,w] = ndgrid(<6 values of zeta>,<9 values of w>) M.SamplingGrid = struct('zeta',zeta,'w',w)
When you displayM
, each entry in the array includes the correspondingzeta
和w
values.
M
M(:,:,1,1) [zeta=0.3, w=5] = 25 -------------- s^2 + 3 s + 25 M(:,:,2,1) [zeta=0.35, w=5] = 25 ---------------- s^2 + 3.5 s + 25 ...
For model arrays generated by linearizing a Simulink®模型在多个参数值或操作订单ints, the software populatesSamplingGrid
automatically with the variable values that correspond to each entry in the array. For instance, theSimulink Control Design™commandslinearize
(Simulink Control Design)和slLinearizer
(Simulink Control Design)populateSamplingGrid
automatically.
By default,SamplingGrid
is a structure with no fields.
Object Functions
The following lists contain a representative subset of the functions you can use withss
model objects. In general, any function applicable toDynamic System Modelsis applicable to anss
object.
Linear Analysis
step |
Step response plot of dynamic system; step response data |
impulse |
Impulse response plot of dynamic system; impulse response data |
lsim |
Plot simulated time response of dynamic system to arbitrary inputs; simulated response data |
bode |
Bode plot of frequency response, or magnitude and phase data |
nyquist |
Nyquist plot of frequency response |
nichols |
Nichols chart of frequency response |
bandwidth |
Frequency response bandwidth |
Stability Analysis
Model Transformation
Model Interconnection
Examples
SISO State-Space Model
Create the SISO state-space model defined by the following state-space matrices:
Specify the A, B, C and D matrices, and create the state-space model.
A = [-1.5,-2;1,0]; B = [0.5;0]; C = [0,1]; D = 0; sys = ss(A,B,C,D)
sys = A = x1 x2 x1 -1.5 -2 x2 1 0 B = u1 x1 0.5 x2 0 C = x1 x2 y1 0 1 D = u1 y1 0 Continuous-time state-space model.
Create Discrete-Time State-Space Model
Create a state-space model with a sample time of 0.25 seconds and the following state-space matrices:
Specify the state-space matrices.
A = [0 1;-5 -2]; B = [0;3]; C = [0 1]; D = 0;
指定样品的时间。
Ts = 0.25;
Create the state-space model.
sys = ss(A,B,C,D,Ts);
Continuous-Time MIMO State-Space Model
For this example, consider a cube rotating about its corner with inertia tensorJ
和a damping forceF
of 0.2 magnitude. The input to the system is the driving torque while the angular velocities are the outputs. The state-space matrices for the cube are:
Specify theA
,B
,C
和D
matrices, and create the continuous-time state-space model.
J = [8 -3 -3; -3 8 -3; -3 -3 8]; F = 0.2*eye(3); A = -J\F; B = inv(J); C = eye(3); D = 0; sys = ss(A,B,C,D)
sys = = (x1, x2) x3 x1 -0.04545 -0.02727 -0.02727 x2 -0.02727 -0.04545 -0.02727 x3 -0.02727 -0.02727 -0.04545 B = u1 u2 u3 x1 0.2273 0.1364 0.1364 x2 0.1364 0.2273 0.1364 x3 0.1364 0.1364 0.2273 C = x1 x2 x3 y1 1 0 0 y2 0 1 0 y3 0 0 1 D = u1 u2 u3 y1 0 0 0 y2 0 0 0 y3 0 0 0 Continuous-time state-space model.
sys
is MIMO since the system contains 3 inputs and 3 outputs observed from matricesC
和D
. For more information on MIMO state-space models, seeMIMO State-Space Models.
Discrete-Time MIMO State-Space Model
Create a state-space model using the following discrete-time, multi-input, multi-output state matrices with sample timets = 0.2
seconds:
Specify the state-space matrices and create the discrete-time MIMO state-space model.
A = [-7,0;0,-10]; B = [5,0;0,2]; C = [1,-4;-4,0.5]; D = [0,-2;2,0]; ts = 0.2; sys = ss(A,B,C,D,ts)
sys = A = x1 x2 x1 -7 0 x2 0 -10 B = u1 u2 x1 5 0 x2 0 2 C = x1 x2 y1 1 -4 y2 -4 0.5 D = u1 u2 y1 0 -2 y2 2 0 Sample time: 0.2 seconds Discrete-time state-space model.
Specify State and Input Names for State-Space Model
Create state-space matrices and specify sample time.
A = [0 1;-5 -2]; B = [0;3]; C = [0 1]; D = 0; Ts = 0.05;
Create the state-space model, specifying the state and input names using name-value pairs.
sys = ss(A,B,C,D,Ts,'StateName',{'Position''Velocity'},...'InputName','Force');
The number of state and input names must be consistent with the dimensions ofA
,B
,C
, andD
.
Naming the inputs and outputs can be useful when dealing with response plots for MIMO systems.
step(sys)
Notice the input nameForce
in the title of the step response plot.
State-Space Model with Inherited Properties
For this example, create a state-space model with the same time and input unit properties inherited from another state-space model. Consider the following state-space models:
First, create a state-space modelsys1
with theTimeUnit
和InputUnit
property set to 'minutes
'.
A1 = [-1.5,-2;1,0]; B1 = [0.5;0]; C1 = [0,1]; D1 = 5; sys1 = ss(A1,B1,C1,D1,'TimeUnit','minutes','InputUnit','minutes');
Verify that the time and input unit properties ofsys1
are set to 'minutes
'.
propValues1 = [sys1.TimeUnit,sys1.InputUnit]
propValues1 =1x2 cell{'minutes'} {'minutes'}
Create the second state-space model with properties inherited fromsys1
.
A2 = [7,-1;0,2]; B2 = [0.85;2]; C2 = [10,14]; D2 = 2; sys2 = ss(A2,B2,C2,D2,sys1);
Verify that the time and input units ofsys2
have been inherited fromsys1
.
propValues2 = [sys2.TimeUnit,sys2.InputUnit]
propValues2 =1x2 cell{'minutes'} {'minutes'}
MIMO Static Gain State-Space Model
In this example, you will create a static gain MIMO state-space model.
Consider the following two-input, two-output static gain matrix:
Specify the gain matrix and create the static gain state-space model.
D = [2,4;3,5]; sys1 = ss(D)
sys1 = D = u1 u2 y1 2 4 y2 3 5 Static gain.
Convert Transfer Function to State-Space Model
Compute the state-space model of the following transfer function:
Create the transfer function model.
H = [tf([1 1],[1 3 3 2]) ; tf([1 0 3],[1 1 1])];
Convert this model to a state-space model.
sys = ss(H);
Examine the size of the state-space model.
size(sys)
State-space model with 2 outputs, 1 inputs, and 5 states.
The number of states is equal to the cumulative order of the SISO entries inH(s).
To obtain a minimal realization ofH(s), enter
sys = ss(H,'minimal'); size(sys)
State-space model with 2 outputs, 1 inputs, and 3 states.
The resulting model has an order of three, which is the minimum number of states needed to representH(s). To see this number of states, refactorH(s) as the product of a first-order system and a second-order system.
Extract State-Space Models from Identified Model
For this example, extract the measured and noise components of an identified polynomial model into two separate state-space models.
Load the Box-Jenkins polynomial modelltiSys
inidentifiedModel.mat
.
load('identifiedModel.mat','ltiSys');
ltiSys
is an identified discrete-time model of the form:
, where
represents the measured component and
the noise component.
Extract the measured and noise components as state-space models.
sysMeas = ss(ltiSys,'measured')
sysMeas = A = x1 x2 x1 1.575 -0.6115 x2 1 0 B = u1 x1 0.5 x2 0 C = x1 x2 y1 -0.2851 0.3916 D = u1 y1 0 Input delays (sampling periods): 2 Sample time: 0.04 seconds Discrete-time state-space model.
sysNoise = ss(ltiSys,'noise')
sysNoise = A = x1 x2 x3 x1 1.026 -0.26 0.3899 x2 1 0 0 x3 0 0.5 0 B = v@y1 x1 0.25 x2 0 x3 0 C = x1 x2 x3 y1 0.319 -0.04738 0.07106 D = v@y1 y1 0.04556 Input groups: Name Channels Noise 1 Sample time: 0.04 seconds Discrete-time state-space model.
The measured component can serve as a plant model, while the noise component can be used as a disturbance model for control system design.
Explicit Realization of Descriptor State-Space Model
Create a descriptor state-space model (E≠I).
= (2 4;4 2];b = [1;0.5);c = [-0.5, 2];d= [-1]; e = [1 0; -3 0.5]; sysd = dss(a,b,c,d,e);
Compute an explicit realization of the system (E=I).
syse = ss(sysd,'explicit')
syse = 4 = (x1, x2) x1 2 x2 -20 B = u1 x1 1 x2-5 C = x1 x2 y1 -0.5 -2 D = u1 y1 -1 Continuous-time state-space model.
Confirm that the descriptor and explicit realizations have equivalent dynamics.
bodeplot(sysd,syse,'g--')
Create State-Space Model with Both Fixed and Tunable Parameters
This example shows how to create a state-spacegenss
model having both fixed and tunable parameters.
wherea和bare tunable parameters, whose initial values are-1
和3
, respectively.
Create the tunable parameters usingrealp
.
a = realp('a',-1); b = realp('b',3);
Define a generalized matrix using algebraic expressions ofa
和b
.
A = [1 a+b;0 a*b];
A
is a generalized matrix whoseBlocks
property containsa
和b
. The initial value ofA
is[1 2;0 -3]
, from the initial values ofa
和b
.
Create the fixed-value state-space matrices.
B = [-3.0;1.5]; C = [0.3 0]; D = 0;
Usess
to create the state-space model.
sys = ss(A,B,C,D)
Generalized continuous-time state-space model with 1 outputs, 1 inputs, 2 states, and the following blocks: a: Scalar parameter, 2 occurrences. b: Scalar parameter, 2 occurrences. Type "ss(sys)" to see the current value and "sys.Blocks" to interact with the blocks.
sys
is a generalized LTI model (genss
) with tunable parametersa
和b
.
State-Space Model with Input and Output Delay
For this example, consider a SISO state-space model defined by the following state-space matrices:
Considering an input delay of 0.5 seconds and an output delay of 2.5 seconds, create a state-space model object to represent the A, B, C and D matrices.
A = [-1.5,-2;1,0]; B = [0.5;0]; C = [0,1]; D = 0; sys = ss(A,B,C,D,'InputDelay',0.5,'OutputDelay',2.5)
sys = A = x1 x2 x1 -1.5 -2 x2 1 0 B = u1 x1 0.5 x2 0 C = x1 x2 y1 0 1 D = u1 y1 0 Input delays (seconds): 0.5 Output delays (seconds): 2.5 Continuous-time state-space model.
You can also use theget
command to display all the properties of a MATLAB object.
get(sys)
A: [2x2 double] B: [2x1 double] C: [0 1] D: 0 E: [] Scaled: 0 StateName: {2x1 cell} StatePath: {2x1 cell} StateUnit: {2x1 cell} InternalDelay: [0x1 double] InputDelay: 0.5000 OutputDelay: 2.5000 InputName: {''} InputUnit: {''} InputGroup: [1x1 struct] OutputName: {''} OutputUnit: {''} OutputGroup: [1x1 struct] Notes: [0x1 string] UserData: [] Name: '' Ts: 0 TimeUnit: 'seconds' SamplingGrid: [1x1 struct]
For more information on specifying time delay for an LTI model, seeSpecifying Time Delays.
Stability Analysis of State-Space Systems
For this example, consider a state-space system object that represents the following state matrices:
Create a state-space objectsys
using thess
command.
A = [-1.2,-1.6,0;1,0,0;0,1,0]; B = [1;0;0]; C = [0,0.5,1.3]; D = 0; sys = ss(A,B,C,D);
Next, compute the closed-loop state-space model for a unit negative gain and find the poles of the closed-loop state-space system objectsysFeedback
.
sysFeedback = feedback(sys,1); P = pole(sysFeedback)
P =3×1 complex-0.2305 + 1.3062i -0.2305 - 1.3062i -0.7389 + 0.0000i
The feedback loop for unit gain is stable since all poles have negative real parts. Checking the closed-loop poles provides a binary assessment of stability. In practice, it is more useful to know how robust (or fragile) stability is. One indication of robustness is how much the loop gain can change before stability is lost. You can use the root locus plot to estimate the range ofk
values for which the loop is stable.
rlocus(sys)
Changes in the loop gain are only one aspect of robust stability. In general, imperfect plant modeling means that both gain and phase are not known exactly. Since modeling errors have the most detrimental effect near the gain crossover frequency (frequency where open-loop gain is 0dB), it also matters how much phase variation can be tolerated at this frequency.
You can display the gain and phase margins on a Bode plot as follows.
bode(sys) grid
For a more detailed example, seeAssessing Gain and Phase Margins.
Control Design using State-Space Models
For this example, design a 2-DOF PID controller with a target bandwidth of 0.75 rad/s for a system represented by the following matrices:
Create a state-space objectsys
using thess
command.
A = [-0.5,-0.1;1,0]; B = [1;0]; C = [0,1]; D = 0; sys = ss(A,B,C,D)
sys = A = x1 x2 x1 -0.5 -0.1 x2 1 0 B = u1 x1 1 x2 0 C = x1 x2 y1 0 1 D = u1 y1 0 Continuous-time state-space model.
Using the target bandwidth, usepidtune
to generate a 2-DOF controller.
wc = 0.75; C2 = pidtune(sys,'PID2',wc)
C2 = 1 u = Kp (b*r-y) + Ki --- (r-y) + Kd*s (c*r-y) s with Kp = 0.513, Ki = 0.0975, Kd = 0.577, b = 0.344, c = 0 Continuous-time 2-DOF PID controller in parallel form.
Using the type'PID2'
causespidtune
to generate a 2-DOF controller, represented as apid2
object. The display confirms this result. The display also shows thatpidtune
tunes all controller coefficients, including the setpoint weightsb
和c
, to balance performance and robustness.
For interactive PID tuning in the Live Editor, see theTune PID ControllerLive Editor task. This task lets you interactively design a PID controller and automatically generates MATLAB code for your live script.
For interactive PID tuning in a standalone app, usePID Tuner. SeePID Controller Design for Fast Reference Trackingfor an example of designing a controller using the app.
Connect Specific Inputs and Outputs of State-Space Models in a Feedback Loop
Consider a state-space plantG
with five inputs and four outputs and a state-space feedback controllerK
with three inputs and two outputs. The outputs 1, 3, and 4 of the plantG
must be connected the controllerK
inputs, and the controller outputs to inputs 4 and 2 of the plant.
For this example, consider two continuous-time state-space models for bothG
和K
represented by the following set of matrices:
AG = [-3,0.4,0.3;-0.5,-2.8,-0.8;0.2,0.8,-3]; BG = [0.4,0,0.3,0.2,0;-0.2,-1,0.1,-0.9,-0.5;0.6,0.9,0.5,0.2,0]; CG = [0,-0.1,-1;0,-0.2,1.6;-0.7,1.5,1.2;-1.4,-0.2,0]; DG = [0,0,0,0,-1;0,0.4,-0.7,0,0.9;0,0.3,0,0,0;0.2,0,0,0,0]; sysG = ss(AG,BG,CG,DG)
sysG = A = x1 x2 x3 x1 -3 0.4 0.3 x2 -0.5 -2.8 -0.8 x3 0.2 0.8 -3 B = u1 u2 u3 u4 u5 x1 0.4 0 0.3 0.2 0 x2 -0.2 -1 0.1 -0.9 -0.5 x3 0.6 0.9 0.5 0.2 0 C = x1 x2 x3 y1 0 -0.1 -1 y2 0 -0.2 1.6 y3 -0.7 1.5 1.2 y4 -1.4 -0.2 0 D = u1 u2 u3 u4 u5 y1 0 0 0 0 -1 y2 0 0.4 -0.7 0 0.9 y3 0 0.3 0 0 0 y4 0.2 0 0 0 0 Continuous-time state-space model.
AK = [-0.2,2.1,0.7;-2.2,-0.1,-2.2;-0.4,2.3,-0.2]; BK = [-0.1,-2.1,-0.3;-0.1,0,0.6;1,0,0.8]; CK = [-1,0,0;-0.4,-0.2,0.3]; DK = [0,0,0;0,0,-1.2]; sysK = ss(AK,BK,CK,DK)
sysK = A = x1 x2 x3 x1 -0.2 2.1 0.7 x2 -2.2 -0.1 -2.2 x3 -0.4 2.3 -0.2 B = u1 u2 u3 x1 -0.1 -2.1 -0.3 x2 -0.1 0 0.6 x3 1 0 0.8 C = x1 x2 x3 y1 -1 0 0 y2 -0.4 -0.2 0.3 D = u1 u2 u3 y1 0 0 0 y2 0 0 -1.2 Continuous-time state-space model.
Define thefeedout
和feedin
vectors based on the inputs and outputs to be connected in a feedback loop.
feedin = [4 2]; feedout = [1 3 4]; sys = feedback(sysG,sysK,feedin,feedout,-1)
sys = A = x1 x2 x3 x4 x5 x6 x1 -3 0.4 0.3 0.2 0 0 x2 1.18 -2.56 -0.8 -1.3 -0.2 0.3 x3 -1.312 0.584 -3 0.56 0.18 -0.27 x4 2.948 -2.929 -2.42 -0.452 1.974 0.889 x5 -0.84 -0.11 0.1 -2.2 -0.1 -2.2 x6 -1.12 -0.26 -1 -0.4 2.3 -0.2 B = u1 u2 u3 u4 u5 x1 0.4 0 0.3 0.2 0 x2 -0.44 -1 0.1 -0.9 -0.5 x3 0.816 0.9 0.5 0.2 0 x4 -0.2112 -0.63 0 0 0.1 x5 0.12 0 0 0 0.1 x6 0.16 0 0 0 -1 C = x1 x2 x3 x4 x5 x6 y1 0 -0.1 -1 0 0 0 y2 -0.672 -0.296 1.6 0.16 0.08 -0.12 y3 -1.204 1.428 1.2 0.12 0.06 -0.09 y4 -1.4 -0.2 0 0 0 0 D = u1 u2 u3 u4 u5 y1 0 0 0 0 -1 y2 0.096 0.4 -0.7 0 0.9 y3 0.072 0.3 0 0 0 y4 0.2 0 0 0 0 Continuous-time state-space model.
size(sys)
State-space model with 4 outputs, 5 inputs, and 6 states.
sys
is the resultant closed loop state-space model obtained by connecting the specified inputs and outputs ofG
和K
.
Version History
Introduced before R2006a
Beispiel öffnen
Sie haben eine geänderte Version dieses Beispiels. Möchten Sie dieses Beispiel mit Ihren Änderungen öffnen?
MATLAB-Befehl
Sie haben auf einen Link geklickt, der diesem MATLAB-Befehl entspricht:
Führen Sie den Befehl durch Eingabe in das MATLAB-Befehlsfenster aus. Webbrowser unterstützen keine MATLAB-Befehle.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina(Español)
- Canada(English)
- United States(English)
Europe
- Belgium(English)
- Denmark(English)
- Deutschland(Deutsch)
- España(Español)
- Finland(English)
- France(Français)
- 爱尔兰(English)
- Italia(Italiano)
- Luxembourg(English)
- Netherlands(English)
- Norway(English)
- Österreich(Deutsch)
- Portugal(English)
- Sweden(English)
- Switzerland
- United Kingdom(English)