If you estimated a linear model from detrended data and want to simulate or predict the
output at the original operation conditions, use retrend
to add trend data back into the simulated or predicted output.
Command | Description | Example |
---|---|---|
compare |
Determine how closely the simulated model response matches the measured output signal. Plots simulated or predicted output of one or more models on top of the measured output. You should use an independent validation data set as input to the model. |
To plot five-step-ahead predicted output of the model compare(data,mod,5) NoteOmitting the third argument assumes an infinite horizon and results in the comparison of the simulated response to the input data. |
sim |
Simulate and plot the model output only. |
To simulate the response of the model sim(model,data) |
predict |
Predict and plot the model output only. |
To perform one-step-ahead prediction of the response for the model
predict(model,data,1) Use the following syntax to compute yhat = predict(m,[y u],k)
|
forecast |
Forecast a time series into the future. |
To forecast the value of a time series in an arbitrary number of steps into the future, use the following command: forecast(model,past_data,K) Here, |
The process of computing simulated and predicted responses over a time range starts by
using the initial conditions to compute the first few output values. sim
,
forecast
, and predict
commands provide defaults for
handling initial conditions.
Simulation: Default initial conditions are zero for all
model types except idnlgrey
model, in which case the default initial
conditions are the internal model initial states (model property x0
). You can
specify other initial conditions using the InitialCondition
simulation option
(see simOptions
).
Use the compare
command to validate models by simulation because its
algorithm estimates the initial states of a model to optimize the model fit to a given data
set.
If you use sim
, the simulated and the measured responses might differ
when the initial conditions of the estimated model and the system that measured the validation
data set differ—especially at the beginning of the response. To minimize this difference,
estimate the initial state values from the data using findstates
and
specify these initial states using the InitialCondition
simulation option
(see simOptions
). For example, to compute the initial states that optimize the fit of
the model m
to the output data in z
:
% Estimate the initial states X0est = findstates(m,z); % Simulate the response using estimated initial states opt = simOptions('InitialCondition',X0est); sim(m,z.InputData,opt)
Prediction: Default initial conditions depend on the type
of model. You can specify other initial conditions using the InitialCondition
option (see predictOptions
). For example, to compute the initial
states that optimize the 1-step-ahead predicted response of the model m
to
the output data z
:
opt = predictOptions('InitialCondition','estimate'); [Yp,X0est] = predict(m,z,1,opt);
This command returns the estimated initial states as the output argument
X0est
. For information about other ways to specify initials states, see the
predictOptions
reference page.
This example shows how to simulate a continuous-time state-space model using a random binary input u
and a sample time of 0.1 s
.
Consider the following state-space model:
where e is Gaussian white noise with variance 7.
Create a continuous-time state-space model.
A = [-1 1; -0.5 0]; B = [1;0.5]; C = [1 0]; D = 0; K = [0.5;0.5]; % Ts = 0 indicates continuous time model_ss = idss(A,B,C,D,K,'Ts',0,'NoiseVariance',7);
Create a random binary input.
u = idinput(400,'rbs',[0 0.3]);
Create an iddata
object with empty output to represent just the input signal.
data = iddata([],u); data.ts = 0.1;
Simulate the output using the model
opt = simOptions('AddNoise',true);
y = sim(model_ss,data,opt);
This example shows how you can create input data and a model, and then use the data and the model to simulate output data.
In this example, you create the following ARMAX model with Gaussian noise e:
Then, you simulate output data with random binary input u
.
Create an ARMAX model.
m_armax = idpoly([1 -1.5 0.7],[0 1 0.5],[1 -1 0.2]);
Create a random binary input.
u = idinput(400,'rbs',[0 0.3]);
Simulate the output data.
opt = simOptions('AddNoise',true);
y = sim(m_armax,u,opt);
The 'AddNoise'
option specifies to include in the simulation the Gaussian noise e
present in the model. Set this option to false
(default behavior) to simulate the noise-free response to the input u
, which is equivalent to setting e
to zero.
compare
| forecast
| predict
| sim