| System Identification Toolbox™ | ![]() |
YS = sim(MODEL,U)
YS = sim(MODEL,U,'Noise')
YS = sim(MODEL,U,'InitialState',INIT)
YS = sim(MODEL,U) simulates a dynamic system with an idnlarx model.
YS = sim(MODEL,U,'Noise') produces a noise corrupted simulation with an additive Gaussian noise scaled according to the value of the NoiseVariance property of MODEL.
YS = sim(MODEL,U,'InitialState',INIT) specifies the initial conditions for simulation using various options, such as numerical initial state vector or past I/O data.
To simulate the model with user-defined noise, set the input U = [UIN E], where UIN is the input signal and E is the noise signal. UIN and E must both be one of the following:
iddata objects: E stores the noise signals as inputs, where the number of inputs matches the number of model outputs.Ny is the number of model outputs.
Matrices: E has as many columns as there are noise signals, corresponding to the number of model outputs.
MODEL: idnlarx model object.
U: Input data for simulation, an iddata object (where only the input channels are used) or a matrix. For noisy simulations, U contains both input and noise channels.
INIT: Initial condition specification. INIT can be one of the following:
A real column vector X0, for the state vector corresponding to an appropriate number of output and input data samples prior to the simulation start time. To build an initial state vector from a given set of input-output data or to generate equilibrium states, see data2state(idnlarx), findstates(idnlarx) and findop(idnlarx). For multi-experiment data, X0 may be a matrix whose columns give different initial states for different experiments.
'z': (Default) Zero initial state, equivalent to a zero vector of appropriate size.
iddata object containing output and input data samples prior to the simulation start time. If it contains more data samples than necessary, only the last samples are taken into account. This syntax is equivalent tosim(MODEL, U, 'InitialState', data2state(MODEL,INIT)) where data2state(idnlarx) transforms the iddata object INIT to a state vector.
YS: Simulated output. An iddata object if U is an iddata object, a matrix otherwise.
Note If sim is called without an output argument, MATLAB® software displays the simulated output(s) in a plot window. |
In this example you simulate a single-input single-output idnlarx model M about a known equilibrium condition, with an input level of 1 and output level of 10.
Load sample data.
load iddata2;
Estimate an idnlarx model from data.
M = nlarx(z2, [2 2 1], 'tree');
Estimate current states of model based on past data.
x0 = data2state(M, struct('Input',1, 'Output', 10));
Simulate the model using the initial states returned by data2state.
sim(M, z2, 'init', x0);
MATLAB software responds with a plot of the simulated response.

In this example you continue the simulation of a model from the end of a previous simulation run.
Estimate the idnlarx model from data.
load iddata2 M = nlarx(z2, [2 2 1], 'tree'); % idnlarx model
Simulate the model using first half of input data of z2
u1 = z2(1:200,[]); % Simulate starting from zero initial states ys1 = sim(M, u1, 'init', 'z');
Start another simulation, using the same states of the model from when the first simulation ended. For the second simulation, you use the second half of the input data of z2.
% input data for next simulation (second half of z2's input) u2 = z2(201:end, []);
In order to set the initial states for second simulation correctly, package input u1 and output ys1 from the first simulation into one iddata object.
firstSimData = [ys1,u1];
Pass this data as initial conditions for the next simulation.
ys2 = sim(M, u2, 'init', firstSimData);
Verify the two simulations by comparing to a complete simulation using all the input data of z2.
uTotal = z2(:,[]); % extract the whole input data ysTotal = sim(M, uTotal, 'init', 'z'); % Compare the values of ys1, ys2 and ysTotal. % ys1 should be equal to first half of ysTotal. % ys2 should be equal to the second half of ysTotal plot(ys1,'b', ys2, 'g', ysTotal, 'k*') % plot the three responses
MATLAB software responds with a plot showing the three responses, with ysTotal overlaying ys1 and ys2 to verify that they match.

In this example, you estimate initial states of model M such that the response best matches the output in data setz2.
Load the sample data and create data object z2.
load iddata2; z2 = z2(1:50);
Estimate idnlarx model from data.
M = nlarx(z2,[4 3 2],'wave');
Estimate initial states of M to best fit z2.y in the simulated response.
x0 = findstates(M, z2, [], 'sim');
Simulate the model.
sim(M, z2.u, 'init', x0)
MATLAB software responds with the following plot.

In this example you start simulation of a model about a steady-state condition, where the input is known to be 1, but the output is unknown.
Load sample data and create data object z2.
load iddata2 z2 = z2(1:50);
Estimate idnlarx model from data.
M = nlarx(z2, [4 3 2], 'wave');
Determine equilibrium state values for input 1 and the unknown target output.
x0 = findop(M, 'steady', 1, NaN);
Simulate the model using initial states x0.
sim(M, z2.u, 'init', x0)
MATLAB software responds with the following plot.

| predict(idnlarx) | |
| findop(idnlarx) | |
| data2state(idnlarx) | |
| finstates(idnlarx) |
![]() | sim | sim(idnlgrey) | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |