Documentation 
You primarily use a model is to simulate its output, i.e., calculate the output (y(t)) for given input values. You can also predict model output, i.e., compute a qualified guess of future output values based on past observations of system's inputs and outputs. For more information, see Definition: Simulation and Prediction.
You also validate linear parametric models and nonlinear models by checking how well the simulated or predicted output of the model matches the measured output. You can use either time or frequency domain data for simulation or prediction. For frequency domain data, the simulation and prediction results are products of the Fourier transform of the input and frequency function of the model. For more information, see Simulation and Prediction in the App and Simulation and Prediction at the Command Line.
Simulation provides a better validation test for the model than prediction. However, how you validate the model output should match how you plan to use the model. For example, if you plan to use your model for control design, you can validate the model by predicting its response over a time horizon that represents the dominating time constants of the model.
Simulation means computing the model response using input data and initial conditions. The time samples of the model response match the time samples of the input data used for simulation.
For a continuoustime system, simulation means solving a differential equation. For a discretetime system, simulation means directly applying the model equations.
For example, consider a dynamic model described by a firstorder difference equation that uses a sampling interval of 1 second:
y(t) + ay(t–1) = bu(t–1),
where y is the output and u is the input. For parameter values a = –0.9 and b = 1.5, the equation becomes:
y(t) – 0.9y(t–1) = 1.5u(t–1).
Suppose you want to compute the values y(1), y(2), y(3),... for given input values u(0) = 2, u(1) = 1, u(2) = 4,...Here, y(1) is the value of output at the first sampling instant. Using initial condition of y(0) = 0, the values of y(t) for times t = 1, 2 and 3 can be computed as:
y(1) = 0.9y(0) + 1.5u(0) = 0.9*0 + 1.5*2 = 3
y(2) = 0.9y(1) + 1.5u(1) = 0.9*3 + 1.5*1 = 4.2
y(3) = 0.9y(2) + 1.5u(2) = 0.9*4.2 + 1.5*4 = 9.78
...
Prediction forecasts the model response k steps ahead into the future using the current and past values of measured input and output values. k is called the prediction horizon, and corresponds to predicting output at time kT_{s}, where T_{s} is the sampling interval.
For example, suppose you use sensors to measure the input signal u(t) and output signal y(t) of the physical system, described in the previous firstorder equation. At the tenth sampling instant (t = 10), the output y(10) is 16 mm and the corresponding input u(10) is 12 N. Now, you want to predict the value of the output at the future time t = 11. Using the previous equation:
y(11) = 0.9y(10) + 1.5u(10)
Hence, the predicted value of future output y(11) at time t = 10 is:
y(11) = 0.9*16 + 1.5*12 = 32.4
In general, to predict the model response k steps into the future (k≥1) from the current time t, you should know the inputs up to time t+k and outputs up to time t:
y_{p}(t+k)
= f(u(t+k),u(t+k–1),...,u(t),u(t–1),...,u(0)
y(t),y(t–1),y(t–2),...,y(0))
u(0) and y(0) are the initial states. f() represents the predictor, which is a dynamic model whose form depends on the model structure. For example, the onestepahead predictor y_{p} of the model y(t) + ay(t–1) = bu(t) is:
y_{p}(t+1) = –ay(t) + bu(t+1)
The difference between prediction and simulation is that in prediction, the past values of outputs used for calculation are measured values while in simulation the outputs are themselves a result of calculation using inputs and initial conditions.
The way information in past outputs is used depends on the disturbance model H of the model. For the previous dynamic model, $$H(z)=\frac{1}{1+a{z}^{1}}$$. In models of OutputError (OE) structure (H(z) = 1), there is no information in past outputs that can be used for predicting future output values. In this case, predictions and simulations coincide. For statespace models (idss), outputerror structure corresponds to models with K=0. For polynomial models (idpoly), this corresponds to models with polynomials a=c=d=1.
Note: Prediction with k=∞ means that no previous outputs are used in the computation and prediction returns the same result as simulation. 
Both simulation and prediction require initial conditions, which correspond to the states of the model at the beginning of the simulation or prediction.
To create a model output plot for parametric linear and nonlinear models in the System Identification app, select the Model output check box in the Model Views area. By default, this operation estimates the initial states from the data and plots the output of selected models for comparison.
To include or exclude a model on the plot, click the corresponding model icon in the System Identification app. Active models display a thick line inside the Model Board icon.
To learn how to interpret the model output plot, see Interpreting the Model Output Plot.
To change plot settings, see Changing Model Output Plot Settings.
For general information about creating and working with plots, see Working with Plots.
The following figure shows a sample Model Output plot, created in the System Identification app.
The model output plot shows different information depending on the domain of the inputoutput validation data, as follows:
For timedomain validation data, the plot shows simulated or predicted model output.
For frequencydomain data, the plot shows the amplitude of the model response to the frequencydomain input signal. The model response is equal to the product of the Fourier transform of the input and the model's frequency function.
For frequencyresponse data, the plot shows the amplitude of the model frequency response.
For linear models, you can estimate a model using timedomain data, and then validate the model using frequency domain data. For nonlinear models, you can only use timedomain data for both estimation and validation.
The right side of the plot displays the percentage of the output that the model reproduces (Best Fit), computed using the following equation:
$$\text{BestFit}=\left(1\frac{\lefty\widehat{y}\right}{\lefty\overline{y}\right}\right)\times 100$$
In this equation, y is the measured output, $$\widehat{y}$$ is the simulated or predicted model output, and $$\overline{y}$$ is the mean of y. 100% corresponds to a perfect fit, and 0% indicates that the fit is no better than guessing the output to be a constant ($$\widehat{y}=\overline{y}$$).
Because of the definition of Best Fit, it is possible for this value to be negative. A negative best fit is worse than 0% and can occur for the following reasons:
The estimation algorithm failed to converge.
The model was not estimated by minimizing $$\lefty\widehat{y}\right$$. Best Fit can be negative when you minimized 1stepahead prediction during the estimation, but validate using the simulated output $$\widehat{y}$$.
The validation data set was not preprocessed in the same way as the estimation data set.
The following table summarizes the Model Output plot settings.
Model Output Plot Settings
Action  Command 

Display confidence intervals. 

Change between simulated output or predicted output. 

Display the actual output values (Signal plot), or the difference between model output and measured output (Error plot).  Select Options > Signal plot or Options > Error plot. 
(Timedomain validation data only)  Select Options > Customized time span for fit and enter the minimum and maximum time values. For example: [1 20] 
(Multipleoutput system only)  Select the output by name in the Channel menu. 
The confidence interval corresponds to the range of output values with a specific probability of being the actual output of the system. The toolbox uses the estimated uncertainty in the model parameters to calculate confidence intervals and assumes the estimates have a Gaussian distribution.
For example, for a 95% confidence interval, the region around the nominal curve represents the range of values that have a 95% probability of being the true system response. You can specify the confidence interval as a probability (between 0 and 1) or as the number of standard deviations of a Gaussian distribution. For example, a probability of 0.99 (99%) corresponds to 2.58 standard deviations.
Note: The calculation of the confidence interval assumes that the model sufficiently describes the system dynamics and the model residuals pass independence tests. 
In the app, you can display a confidence interval on the plot to gain insight into the quality of a linear model. To learn how to show or hide confidence interval, see Changing Model Output Plot Settings.
Note: If you estimated a linear model from detrended data and want to simulate or predict the output at the original operation conditions, use the retrend command to the simulated or predicted output. 
Command  Description  Example 

compare  Use this command for model validation to 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 fivestepahead predicted output of the model mod against the validation data data, use the following command: compare(data,mod,5) 
sim  Simulate and plot the model output only.  To simulate the response of the model model using input data data, use the following command: sim(model,data) 
predict  Predict and plot the model output only.  To perform onestepahead prediction of the response for the model model and input data data, use the following command: predict(model,data,1) Use the following syntax to compute kstepahead prediction of the output signal using model m: yhat = predict(m,[y u],k) Note that predict computes the prediction results only over the time range of data. It does not perform any forecasting of results beyond the available data range. 
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, model is a time series model, past_data is a record of the observed values of the time series and K is the forecasting horizon. 
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 polynomial (idpoly), process (idproc) and transferfunction (idtf) models . For statespace (idss) and greybox (idgrey) models, 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 the findstates command and specify these initial states as input arguments to the sim command. 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)
See Also: sim (for linear models), sim(idnlarx), sim(idnlgrey), sim(idnlhw)
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 1stepahead 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 predict reference page for the corresponding model type.
See Also: predict
This example shows how to validate an estimated model by comparing the simulated model output with measured data.
Create estimation and validation data.
load iddata1;
ze = z1(1:150);
zv = z1(151:300);
Estimate an ARMAX model.
m = armax(ze,[2 3 1 0]);
Compare simulated model output with measured data.
compare(zv,m);
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 noisefree response to the input u , which is equivalent to setting e to zero.
This example shows how to simulate a continuoustime statespace model using a random binary input u and a sampling interval of 0.1 s.
Consider the following statespace model:
where e is Gaussian white noise with variance 7.
Create a continuoustime statespace 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 to evaluate how well a timeseries model predicts the response for a given prediction horizon.
In this example, y is the original series of monthly sales figures. You use the first half of the measured data to estimate the timeseries model and test the model's ability to forecast sales six months ahead using the entire data set.
Simulate figures for sales growth every month before settling down.
rng('default');
t = (0:0.2:19)';
yd = 1exp(0.2*t) + randn(size(t))/50;
y = iddata(yd,[],0.2);
plot(y);
Select the first half as estimation data.
y1 = y(1:48);
Estimate a secondorder autoregressive model with noise integration using the data.
m = ar(y1, 2, 'yw', 'IntegrateNoise', true);
Compute 6step ahead predicted output.
yhat = predict(m,y,6);
Forecast the response 10 steps beyond the available data's time range.
yfuture = forecast(m,y,10);
Plot the measured, predicted and forecasted outputs.
plot(y,yhat,yfuture); legend({'measured', 'predicted', 'forecasted'},'location','southeast');