Simulate nonlinear ARX model
YS = sim(MODEL,U)
YS = sim(MODEL,U,'Noise')
YS = sim(MODEL,U,'InitialState',INIT)
YS = sim(MODEL,U) simulates a dynamic system
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
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
= [UIN E], where
UIN is the input signal
E is the noise signal.
both be one of the following:
the noise signals as inputs, where the number of inputs matches the
number of model outputs.
E has as many columns
as there are noise signals, corresponding to the number of model outputs.
U: Input data for simulation, an
(where only the input channels are used) or a matrix. For simulations
with noisy data,
U contains both input and noise
INIT: Initial condition specification.
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
findop. For multi-experiment
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 to
INIT to a
YS: Simulated output. An
U is an
iddata object, a
Simulate a single-input single-output
a known equilibrium point, with an input level of 1 and output level
Load the sample data.
idnlarx model from
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
sim(M, z2, 'init', x0);
Continue the simulation of a nonlinear ARX model from the end of a previous simulation run.
Estimate a nonlinear ARX model from data.
load iddata2 M = nlarx(z2, [2 2 1], 'tree');
Simulate the model using the first half of the input data
z2. Start the simulation from zero initial states.
u1 = z2(1:200,); ys1 = sim(M, u1, 'init', 'z');
Start another simulation using the second half of the input data
z2. Use the same states of the model from when the first simulation ended.
u2 = z2(201:end, );
To set the initial states for second simulation correctly, package input
u1 and output
ys1 from the first simulation into one
iddata object. Pass this data as initial conditions for the next simulation.
firstSimData = [ys1,u1]; ys2 = sim(M, u2, 'init', firstSimData);
Verify the two simulations by comparing to a complete simulation using all the input data
uTotal = z2(:,); % extract the whole input data ysTotal = sim(M, uTotal, 'init', 'z');
Compare the three responses
ysTotal by plotting them.
ys1 should be equal to first half of
ys2 should be equal to the second half of
plot(ys1,'b', ys2, 'g', ysTotal, 'k*')
The plot shows that the three responses
Estimate initial states of model
M such that
the response best matches the output in data set
Load the sample data and create data object
load iddata2; z2 = z2(1:50);
idnlarx model from data.
M = nlarx(z2,[4 3 2],'wave');
Estimate initial states of
z2.y in the simulated response.
x0 = findstates(M,z2,,'sim');
Simulate the model.
ysim = sim(M, z2.u, 'init', x0)
ysim with the output signal
time = z2.SamplingInstants; plot(time, ysim, time, z2.y,'.')
Start simulation of a model near steady state, where the input is known to be 1, but the output is unknown.
Load sample data and create data object
load iddata2 z2 = z2(1:50);
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
sim(M, z2.u, 'init', x0)