# 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`

(Control System Toolbox)
and `reducespec`

(Control System Toolbox)
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 a`LineSpec`

value, see`lsimplot`

.

### 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 (Control System Toolbox).

## Examples

## Input Arguments

## Output Arguments

## Algorithms

For a discrete-time transfer function,

$$sys\left({z}^{-1}\right)=\frac{{a}_{0}+{a}_{1}{z}^{-1}+\dots +{a}_{n}{z}^{-n}}{1+{b}_{1}{z}^{-1}+\dots +{b}_{n}{z}^{-n}},$$

`lsim`

filters the input based on the recursion associated with this
transfer function:

$$y\left[k\right]={a}_{0}u\left[k\right]+\dots +{a}_{n}u\left[k-n\right]-{b}_{1}y\left[k-1\right]-\dots -{b}_{n}\left[k-n\right].$$

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,

$$\begin{array}{c}x\left[n+1\right]=Ax\left[n\right]+Bu\left[n\right],\\ y\left[n\right]=Cx\left[n\right]+Du\left[n\right].\end{array}$$

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

## Version History

**Introduced in R2012a**