Categories &

Functions List

Function Reference: lsim

Function File: lsim (sys, u)
Function File: lsim (sys1, sys2, ..., sysN, u)
Function File: lsim (sys1, style1, ..., sysN, styleN, u)
Function File: lsim (sys1, ..., u, t)
Function File: lsim (sys1, ..., u, t, x0)
Function File: [y, t, x] = lsim (sys, u)
Function File: [y, t, x] = lsim (sys, u, t)
Function File: [y, t, x] = lsim (sys, u, t, x0)
Function File: [...] = lsim (..., method)

Simulate LTI model response to arbitrary inputs. If no output arguments are given, the system response is plotted on the screen.

Inputs

sys

LTI model. System must be proper, i.e. it must not have more zeros than poles.

u

Vector or array of input signal. Needs length(t) rows and as many columns as there are inputs. If sys is a single-input system, row vectors u of length length(t) are accepted as well.

t

Time vector. Should be evenly spaced. If sys is a continuous-time system and t is a real scalar, sys is discretized with sampling time tsam = t/(rows(u)-1). If sys is a discrete-time system and t is not specified, vector t is assumed to be 0 : tsam : tsam*(rows(u)-1).

x0

Vector of initial conditions for each state of a system in state space. If not specified, a zero vector is assumed. Note: A vector x0 provided for an input-output system representation is ignored and a zero vector of initial conditions is used instead because the internally used state space representaton does generally not match the one assumed for x0. For a simulation of an input-output model with initial conditions for the output y and its time-derivatives, see remarks below.

style

Line style and color, e.g. ’r’ for a solid red line or ’-.k’ for a dash-dotted black line. See help plot for details.

method

Method that is used to discretize a continuous-time system for the simulation. See @lti/c2d for possible methods. If method is not provided, the default is ’foh’.

Outputs

y

Output response array. Has as many rows as time samples (length of t) and as many columns as outputs.

t

Time row vector. It is always evenly spaced.

x

State trajectories array. Has length (t) rows and as many columns as states.

Remarks

  • For the simulation, continuous-time systems are discretized using the selected method method or the default first-order-hold method (foh), see @lti/c2d for details.
  • For a SISO input-output model G and initial values for the output y and its derivatives up to order n-1 the corresponding state space represetaiton is computed by:
     [A,b,c,d] = ssdata (G);
     T = obsv (A, c);
     G_ss = ss2ss (ss (G), T);
     initial (G_ss, x0);
     

    Note that, in general, the states of G_ss are only equal to the output y and its first n-1 time derivaties if u=0, which is the case for the initial conditions immediately before t=0.

Source Code: lsim

 

 clf;
 A = [-3   0   0;
       0  -2   1;
      10 -17   0];
 B = [4;
      0;
      0];
 C = [0 0 1];
 D = 0;
 sys = ss(A,B,C,D);
 t = 0:0.01:10;
 u = zeros (length(t) ,1);
 x0 = [0 0.1 0];
 lsim(sys, u, t, x0);

                    
plotted figure