lsim
Compute time response simulation data of dynamic system to arbitrary inputs
Syntax
Description
Response Data
returns the system response y
= lsim(sys
,u
,t
)y
to the input u
,
sampled at the same times t
as the input. For single-output systems,
y
is a vector of the same length as t
. For
multi-output systems, y
is an array having as many rows as there are
time samples and as many columns as there are outputs in sys
.
Input Interpolation Method
State Snapshot POD
Since R2024b
[
performs proper orthogonal decomposition (POD) of the state snapshots for an LTI
state-space model y
,tOut
,x
,~,xPODOut
] = lsim(___,xPODIn
)sys
. Here, xPOD
is an
incrementalPOD
object. You can start a new POD analysis or add to
previous POD results. See incrementalPOD
and reducespec
for examples and model reduction applications.
Response Plots
lsim(___)
plots the simulated time response of
sys
to the input history
(u
,t
) for all of the previous input argument
combinations except state snapshot POD. The plot uses default plotting options. For more
plot customization options, use lsimplot
instead.
To plot responses for multiple dynamic systems on the same plot, you can specify
sys
as a comma-separated list of models. For example,lsim(sys1,sys2,sys3,u,t)
plots the responses for three models on the same plot.To specify a color, line style, and marker for each system in the plot, specify a
LineSpec
value for each system. For example,lsim(sys1,LineSpec1,sys2,LineSpec2,u,t)
plots two models and specifies their plot style. For more information on specifying aLineSpec
value, seelsimplot
.
Linear Simulation Tool
lsim(
opens the Linear Simulation
Tool for simulating sys
)sys
. For more information about using
this tool for linear analysis, see Working with the Linear Simulation Tool.
Examples
Input Arguments
Output Arguments
Algorithms
For a discrete-time transfer function,
lsim
filters the input based on the recursion associated with this
transfer function:
For discrete-time zpk
models, lsim
filters the input
through a series of first-order or second-order sections. This approach avoids forming the
numerator and denominator polynomials, which can cause numerical instability for higher-order
models.
For discrete-time state-space models, lsim
propagates the
discrete-time state-space equations,
For continuous-time systems, lsim
first discretizes the system using
c2d
, and then propagates the resulting discrete-time state-space
equations. Unless you specify otherwise with the method
input argument,
lsim
uses the first-order-hold discretization method when the input
signal is smooth, and zero-order hold when the input signal is discontinuous, such as for
pulses or square waves. The sample time for discretization is the spacing
dT
between the time samples you supply in t
.
For continuous-time sparse and LTV and LPV models, lsim
uses fixed-step
solvers based on the trbdf
or hht
methods (see
SolverOptions
property of sparss
and
mechss
models).