lsim
simulates the (time) responseof continuous or discrete linear systems to arbitrary inputs. Wheninvoked without left-hand arguments, lsim
plotsthe response on the screen.
Description
lsim(sys,u,t)
producesa plot of the time response of the dynamicsystem modelsys
to the inputhistory, t
,u
. The vector t
specifiesthe time samples for the simulation (in system time units, specifiedin the TimeUnit
propertyof sys
), and consists of regularly spaced timesamples:
Developing a dynamic simulation model from first principles is accomplished by expressing the physical system by differential equations. Transient (Dynamic) Modeling in MATLAB / Simulink.
The input u
is an array having as many rowsas time samples (length(t)
) and as many columnsas system inputs. For instance, if sys
is a SISOsystem, then u
is a t-by-1 vector. If sys
hasthree inputs, then u
is a t-by-3 array. Each row u(i,:)
specifiesthe input value(s) at the time sample t(i)
. Thesignal u
also appears on the plot.
The model sys
can be continuous or discrete,SISO or MIMO. In discrete time, u
must be sampledat the same rate as the system. In this case, the input t
isredundant and can be omitted or set to an empty matrix. In continuoustime, the time sampling dt = t(2)-t(1)
is usedto discretize the continuous model. If dt
is toolarge (undersampling), lsim
issues a warning suggestingthat you use a more appropriate sample time, but will use the specifiedsample time. See Algorithms for a discussion of sample times.
lsim(sys,u,t,x0)
furtherspecifies an initial condition x0
for the systemstates. This syntax applies only when sys
is astate-space model. x0
is a vector whose entriesare the initial values of the corresponding states of sys
.
lsim(sys,u,t,x0,method)
explicitly specifieshow the input values should be interpolated between samples, when sys
isa continuous-time system. Specify method
as oneof the following values:
'zoh'
— Use zero-order hold'foh'
— Use linear interpolation(first-order hold)
If you do not specify a method, lsim
selectsthe interpolation method automatically based on the smoothness ofthe signal u
.
lsim(sys1,...,sysn,u,t)
simulates the responsesof several dynamic system models to the same input history t
,u
andplots these responses on a single figure. You can also use the x0
and method
inputarguments when computing the responses of multiple models.
lsim(sys1,LineSpec1,...,sysN,LineSpecN,u,t)
specifies the line style, marker, and color of each of the system responses in the plot. You can also use the x0
and method
input arguments with this syntax. Each LineSpec
argument is specified as a vector of one, two, or three characters. The characters can appear in any order. For example, the following code plots the response of sys1
as a yellow dotted line and the response of sys2
as a green dashed line:
For more information about configuring this argument, see the LineSpec
input argument of the plot
function.
y = lsim(___)
returns the system response y
, sampled at the same times as the input (t
). The output y
is an array having as many rows as time samples (length(t)
) and as many columns as system outputs. No plot is drawn on the screen. You can use this syntax with any of the input arguments described in previous syntaxes except the LineSpec
arguments.
[y,t,x] = lsim(___)
also returns the time vector t
used for simulation and the state trajectories x
(for state-space models only). The output x
has as many rows as time samples (length(t)
) and as many columns as system states. You can use this syntax with any of the input arguments described in previous syntaxes except the LineSpec
arguments.
lsim(sys)
opens the LinearSimulation Tool GUI. For more information about working with thisGUI, see Working with the LinearSimulation Tool.