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
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.
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 simulations
with noisy data, 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
and findop
. 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 to sim(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 |
Simulate a single-input single-output idnlarx
model M
around
a known equilibrium point, with an input level of 1 and output level
of 10.
Load the sample data.
load iddata2;
Estimate an idnlarx
model from
the 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);
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 z2
.
uTotal = z2(:,[]); % extract the whole input data ysTotal = sim(M, uTotal, 'init', 'z');
Compare the three responses ys1
, ys2
and ysTotal
by plotting them. 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*')
The plot shows that the three responses ys1
, ys2
and ysTotal
overlap.
Estimate initial states of model M
such that
the response best matches the output in data set z2
.
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.
ysim = sim(M, z2.u, 'init', x0)
Compare ysim
with the output signal
in z2
:
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 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)