Main Content

ss

State-space model

Description

Usessto create real-valued or complex-valued state-space models, or to convertdynamic system modelsto state-space model form. You can also usessto 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. Thessmodel 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:

x ˙ = A x + B u y = C x + D u

Here,x,uyrepresent the states, inputs and outputs respectively, whileA,B,CDare the state-space matrices. Thessobject represents a state-space model in MATLAB®storingA,B,CDalong 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 anssmodel 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

Description

example

sys= ss(A,B,C,D)creates a continuous-time state-space model object of the following form:

x ˙ = A x + B u y = C x + D u

For instance, consider a plant withNxstates,Nyoutputs, andNuinputs. The state-space matrices are:

  • Ais anNx-by-Nxreal- or complex-valued matrix.

  • Bis anNx-by-Nureal- or complex-valued matrix.

  • Cis anNy-by-Nxreal- or complex-valued matrix.

  • Dis anNy-by-Nureal- or complex-valued matrix.

example

sys= ss(A,B,C,D,ts)creates the discrete-time state-space model object of the following form with the sample timets(in seconds):

x [ n + 1 ] = A x [ n ] + B u [ n ] y [ n ] = C x [ n ] + D u [ n ]

To leave the sample time unspecified, settsto-1.

example

sys= ss(A,B,C,D,ltiSys)creates a state-space model with properties such as input and output names, internal delays and sample time values inherited from the modelltisys.

example

sys= ss(D)creates a state-space model that represents the static gain,D. The output state-space model is equivalent toss([],[],[],D).

example

sys= ss(___,Name,Value)sets properties of the state-space model using one or moreName,Valuepair arguments for any of the previous input-argument combinations.

example

sys= ss(ltiSys)converts the dynamic system modelltiSysto a state-space model. IfltiSyscontains tunable or uncertain elements,ssuses the current or nominal values for those elements respectively.

example

sys= ss(ltiSys,component)converts tossobject form the measured component, the noise component or both of specifiedcomponentof an identified linear time-invariant (LTI) modelltiSys. Use this syntax only whenltiSysis 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.

sys= ss(ssSys,'minimal')returns the minimal state-space realization with no uncontrollable or unobservable states. This realization is equivalent tominreal(ss(sys))where matrixAhas 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.

example

sys= ss(ssSys,'explicit')returns an explicit state-space realization(E = I)of the dynamic system state-space modelssSys.ssreturns an error ifssSysis improper. For more information on explicit state-space realization, seeState-Space Models.

Input Arguments

expand all

State matrix, specified as anNx-by-Nxmatrix where,Nxis the number of states. This input sets the value of propertyA.

Input-to-state matrix, specified as anNx-by-Numatrix where,Nxis the number of states andNuis the number of inputs. This input sets the value of propertyB.

State-to-output matrix, specified as anNy-by-Nxmatrix where,Nxis the number of states andNyis the number of outputs. This input sets the value of propertyC.

Feedthrough matrix, specified as anNy-by-Numatrix where,Nyis the number of outputs andNuis the number of inputs. This input sets the value of propertyD.

Sample time, specified as a scalar. For more information, seeTsproperty.

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 astf,zpk,ss, orpidmodels.

  • Generalized or uncertain LTI models such asgenssoruss(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 asidtf(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,ssconverts the measured component of the identified model by default.(Using identified models requires System Identification Toolbox™ software.)

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.

componentonly applies whensysis an identified LTI model.

For more information on identified LTI models and their measured and noise components, seeIdentified LTI Models.

Dynamic system model to convert to minimal realization or explicit form, specified as anssmodel object.

Output Arguments

expand all

Output system model, returned as:

  • A state-space (ss) model object, when the inputsA,B,CDare 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,CDincludes tunable parameters, such asrealpparameters 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,CDincludes uncertain matrices. Using uncertain models requires Robust Control Toolbox software.

Properties

expand all

State matrix, specified as anNx-by-Nxmatrix whereNxis 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.

Input-to-state matrix, specified as anNx-by-Numatrix whereNxis the number of states andNuis the number of inputs.

State-to-output matrix, specified as anNy-by-Nxmatrix whereNxis the number of states andNyis the number of outputs.

Feedthrough matrix, specified as anNy-by-Numatrix whereNyis the number of outputs andNuis the number of inputs.Dis also called as the static gain matrix which represents the ratio of the output to the input under steady state condition.

Matrix for implicit or descriptor state-space models, specified as aNx-by-Nxmatrix.Eis 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. Seedssfor more information about creating descriptor state-space models.

Logical value indicating whether scaling is enabled or disabled, specified as either0or1.

WhenScaledis set to0(disabled), then most numerical algorithms acting on the state-space modelsysautomatically rescale the state vector to improve numerical accuracy. You can prevent such auto-scaling by settingScaledto1(enabled).

For more information about scaling, seeprescale.

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

StateNameis empty''for all states by default.

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

StatePathis empty''for all states by default.

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

UseStateUnitto keep track of the units of each state.StateUnithas no effect on system behavior.StateUnitis empty''for all states by default.

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 theTimeUnitproperty of the model. For discrete-time models, internal delays are expressed as integer multiples of the sample timeTs. For example,InternalDelay = 3means a delay of three sampling periods.

You can modify the values of internal delays using the propertyInternalDelay. However, the number of entries insys.InternalDelaycannot change, because it is a structural property of the model.

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, whereNuis the number of inputs.

For continuous-time systems, specify input delays in the time unit specified by theTimeUnitproperty. For discrete-time systems, specify input delays in integer multiples of the sample time,Ts.

For more information, seeTime Delays in Linear Systems.

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.

  • Ny1向量-指定单独的输出延迟output of a multi-output system, whereNyis the number of outputs.

For continuous-time systems, specify output delays in the time unit specified by theTimeUnitproperty. For discrete-time systems, specify output delays in integer multiples of the sample time,Ts.

For more information, seeTime Delays in Linear Systems.

Sample time, specified as:

  • 0for continuous-time systems.

  • A positive scalar representing the sampling period of a discrete-time system. SpecifyTsin the time unit specified by theTimeUnitproperty.

  • -1for a discrete-time system with an unspecified sample time.

Note

ChangingTsdoes not discretize or resample the model. To convert between continuous-time and discrete-time representations, usec2dd2c. To change the sample time of a discrete-time system, used2d.

Time variable units, specified as one of the following:

  • 'nanoseconds'

  • 'microseconds'

  • 'milliseconds'

  • 'seconds'

  • 'minutes'

  • 'hours'

  • 'days'

  • 'weeks'

  • 'months'

  • 'years'

ChangingTimeUnithas no effect on other properties, but changes the overall system behavior. UsechgTimeUnitto convert between time units without modifying system behavior.

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, ifsysis 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 notationuto refer to theInputNameproperty. For example,sys.u相当于sys.InputName.

UseInputNameto:

  • Identify channels on model display and plots.

  • Extract subsystems of MIMO systems.

  • Specify connection points when interconnecting models.

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.

UseInputUnitto specify input signal units.InputUnithas no effect on system behavior.

Input channel groups, specified as a structure. UseInputGroupto assign the input channels of MIMO systems into groups and refer to each group by name. The field names ofInputGroupare the group names and the field values are the input channels of each group. For example, enter the following to create input groups namedcontrolsnoisethat include input channels12, and35, respectively.

sys.InputGroup.controls = [1 2]; sys.InputGroup.noise = [3 5];

You can then extract the subsystem from thecontrolsinputs to all outputs using the following.

sys(:,'controls')

By default,InputGroupis a structure with no fields.

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, ifsysis 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 notationyto refer to theOutputNameproperty. For example,sys.y相当于sys.OutputName.

UseOutputNameto:

  • Identify channels on model display and plots.

  • Extract subsystems of MIMO systems.

  • Specify connection points when interconnecting models.

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.

UseOutputUnitto specify output signal units.OutputUnithas no effect on system behavior.

Output channel groups, specified as a structure. UseOutputGroupto assign the output channels of MIMO systems into groups and refer to each group by name. The field names ofOutputGroupare the group names and the field values are the output channels of each group. For example, create output groups namedtemperaturemeasurementthat include output channels1, and35, respectively.

sys.OutputGroup.temperature = [1]; sys.OutputGroup.measurement = [3 5];

You can then extract the subsystem from all inputs to themeasurementoutputs using the following.

sys('measurement',:)

By default,OutputGroupis a structure with no fields.

System name, specified as a character vector. For example,'system_1'.

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'.

User-specified data that you want to associate with the system, specified as any MATLAB data type.

Sampling grid for model arrays, specified as a structure array.

UseSamplingGridto 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,zetaw. 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 correspondingzetawvalues.

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 populatesSamplingGridautomatically 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)populateSamplingGridautomatically.

By default,SamplingGridis a structure with no fields.

Object Functions

The following lists contain a representative subset of the functions you can use withssmodel objects. In general, any function applicable toDynamic System Modelsis applicable to anssobject.

expand all

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
pole Poles of dynamic system
zero Zeros and gain of SISO dynamic system
pzplot Pole-zero plot of dynamic system model with additional plot customization options
margin Gain margin, phase margin, and crossover frequencies
zpk Zero-pole-gain模型
tf Transfer function model
c2d Convert model from continuous to discrete time
d2c Convert model from discrete to continuous time
d2d Resample discrete-time model
feedback Feedback connection of multiple models
connect Block diagram interconnections of dynamic systems
series Series connection of two models
parallel Parallel connection of two models
pidtune PID tuning algorithm for linear plant model
rlocus Root locus plot of dynamic system
lqr Linear-Quadratic Regulator (LQR) design
lqg Linear-Quadratic-Gaussian (LQG) design
lqi Linear-Quadratic-Integral control
kalman Design Kalman filter for state estimation

Examples

collapse all

Create the SISO state-space model defined by the following state-space matrices:

A = [ - 1 . 5 - 2 1 0 ] B = [ 0 . 5 0 ] C = [ 0 1 ] D = 0

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 a state-space model with a sample time of 0.25 seconds and the following state-space matrices:

A = [ 0 1 - 5 - 2 ] B = [ 0 3 ] C = [ 0 1 ] D = [ 0 ]

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);

For this example, consider a cube rotating about its corner with inertia tensorJ和a damping forceFof 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:

A = - J - 1 F , B = J - 1 , C = I , D = 0 , w h e r e , J = [ 8 - 3 - 3 - 3 8 - 3 - 3 - 3 8 ] a n d F = [ 0 . 2 0 0 0 0 . 2 0 0 0 0 . 2 ]

Specify theA,B,CDmatrices, 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.

sysis MIMO since the system contains 3 inputs and 3 outputs observed from matricesCD. For more information on MIMO state-space models, seeMIMO State-Space Models.

Create a state-space model using the following discrete-time, multi-input, multi-output state matrices with sample timets = 0.2seconds:

A = [ - 7 0 0 - 1 0 ] B = [ 5 0 0 2 ] C = [ 1 - 4 - 4 0 . 5 ] D = [ 0 - 2 2 0 ]

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.

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)

Figure contains an axes object. The axes object with title From: Force To: Out(1) contains an object of type line. This object represents sys.

Notice the input nameForcein the title of the step response plot.

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:

A 1 = [ - 1 . 5 - 2 1 0 ] B 1 = [ 0 . 5 0 ] C 1 = [ 0 1 ] D 1 = 5 A 2 = [ 7 - 1 0 2 ] B 2 = [ 0 . 8 5 2 ] C 2 = [ 1 0 1 4 ] D 2 = 2

First, create a state-space modelsys1with theTimeUnitInputUnitproperty 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 ofsys1are 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 ofsys2have been inherited fromsys1.

propValues2 = [sys2.TimeUnit,sys2.InputUnit]
propValues2 =1x2 cell{'minutes'} {'minutes'}

In this example, you will create a static gain MIMO state-space model.

Consider the following two-input, two-output static gain matrix:

D = [ 2 4 3 5 ]

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.

Compute the state-space model of the following transfer function:

H ( s ) = [ s + 1 s 3 + 3 s 2 + 3 s + 2 s 2 + 3 s 2 + s + 1 ]

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.

H ( s ) = [ 1 s + 2 0 0 1 ] [ s + 1 s 2 + s + 1 s 2 + 3 s 2 + s + 1 ]

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 modelltiSysinidentifiedModel.mat.

load('identifiedModel.mat','ltiSys');

ltiSysis an identified discrete-time model of the form: y ( t ) = B F u ( t ) + C D e ( t ) , where B F represents the measured component and C D 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.

Create a descriptor state-space model (EI).

= (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--')

Figure contains 2 axes objects. Axes object 1 with ylabel Magnitude (dB) contains 2 objects of type line. These objects represent sysd, syse. Axes object 2 with ylabel Phase (deg) contains 2 objects of type line. These objects represent sysd, syse.

This example shows how to create a state-spacegenssmodel having both fixed and tunable parameters.

A = [ 1 a + b 0 a b ] , B = [ - 3 . 0 1 . 5 ] , C = [ 0 . 3 0 ] , D = 0 ,

whereabare tunable parameters, whose initial values are-13, respectively.

Create the tunable parameters usingrealp.

a = realp('a',-1); b = realp('b',3);

Define a generalized matrix using algebraic expressions ofab.

A = [1 a+b;0 a*b];

Ais a generalized matrix whoseBlocksproperty containsab. The initial value ofAis[1 2;0 -3], from the initial values ofab.

Create the fixed-value state-space matrices.

B = [-3.0;1.5]; C = [0.3 0]; D = 0;

Usessto 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.

sysis a generalized LTI model (genss) with tunable parametersab.

For this example, consider a SISO state-space model defined by the following state-space matrices:

A = [ - 1 . 5 - 2 1 0 ] B = [ 0 . 5 0 ] C = [ 0 1 ] D = 0

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 thegetcommand 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.

For this example, consider a state-space system object that represents the following state matrices:

A = [ - 1 . 2 - 1 . 6 0 1 0 0 0 1 0 ] , B = [ 1 0 0 ] , C = [ 0 0 . 5 1 . 3 ] , D = 0 , State-space matrices

Create a state-space objectsysusing thesscommand.

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 ofkvalues for which the loop is stable.

rlocus(sys)

Figure contains an axes object. The axes object contains 5 objects of type line. One or more of the lines displays its values using only markers This object represents 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

Figure contains 2 axes objects. Axes object 1 with ylabel Magnitude (dB) contains an object of type line. This object represents sys. Axes object 2 with ylabel Phase (deg) contains an object of type line. This object represents sys.

For a more detailed example, seeAssessing Gain and Phase Margins.

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:

A = [ - 0 . 5 - 0 . 1 1 0 ] , B = [ 1 0 ] , C = [ 0 1 ] , D = 0 .

Create a state-space objectsysusing thesscommand.

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, usepidtuneto 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'causespidtuneto generate a 2-DOF controller, represented as apid2object. The display confirms this result. The display also shows thatpidtunetunes all controller coefficients, including the setpoint weightsbc, 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.

Consider a state-space plantGwith five inputs and four outputs and a state-space feedback controllerKwith three inputs and two outputs. The outputs 1, 3, and 4 of the plantGmust be connected the controllerKinputs, and the controller outputs to inputs 4 and 2 of the plant.

For this example, consider two continuous-time state-space models for bothGKrepresented by the following set of matrices:

A G = [ - 3 0 . 4 0 . 3 - 0 . 5 - 2 . 8 - 0 . 8 0 . 2 0 . 8 - 3 ] , B G = [ 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 ] , C G = [ 0 - 0 . 1 - 1 0 - 0 . 2 1 . 6 - 0 . 7 1 . 5 1 . 2 - 1 . 4 - 0 . 2 0 ] , D G = [ 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 ]

A K = [ - 0 . 2 2 . 1 0 . 7 - 2 . 2 - 0 . 1 - 2 . 2 - 0 . 4 2 . 3 - 0 . 2 ] , B K = [ - 0 . 1 - 2 . 1 - 0 . 3 - 0 . 1 0 0 . 6 1 0 0 . 8 ] , C K = [ - 1 0 0 - 0 . 4 - 0 . 2 0 . 3 ] , D K = [ 0 0 0 0 0 - 1 . 2 ]

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 thefeedoutfeedinvectors 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.

sysis the resultant closed loop state-space model obtained by connecting the specified inputs and outputs ofGK.

Version History

Introduced before R2006a