%% Verify Explicitly Created Diffuse State-Space Model
% An important step in state-space model analysis is to ensure that the software interprets the state and observation equation matrices as you intend. Use disp to help you verify the diffuse state-space model.
% Define a diffuse state-space model, where the state equation is an AR(2) model, and the observation equation is the difference between the current and previous state plus the observation error. Symbolically, the state-space model is
% \left[ {\begin{array}{*{20}{c}}{{x_{1,t}}}\\{{x_{2,t}}}\\{{x_{3,t}}}\end{array}}
% \right] = \left[
% {\begin{array}{*{20}{c}}0.6&0.2&0.5\\1&0&0\\0&0&1\end{array}} \right]\left[
% {\begin{array}{*{20}{c}}{{x_{1,t - 1}}}\\{{x_{2,t - 1}}}\\{{x_{3,t -
% 1}}}\end{array}} \right] + \left[ {\begin{array}{*{20}{c}}{0.3} \\
% 0 \\ 0\end{array}} \right]u_{1,t}
% {y_t} = \left[ {\begin{array}{*{20}{c}}1&-1&0\end{array}}
% \right]\left[
% {\begin{array}{*{20}{c}}{{x_{1,t}}}\\{{x_{2,t}}}\\{{x_{3,t}}}\end{array}}
% \right]+0.1\varepsilon_t.
% Assume the initial state distribution is diffuse.
% There are three states: x_{1,t} is the AR(2) process, x_{2,t} represents x_{1,t-1}, and x_{3,t} is the AR(2) model constant.
% Define the state-transition matrix.

A = [0.6 0.2 0.5; 1 0 0; 0 0 1];

%
% Define the state-disturbance-loading matrix.

B = [0.3; 0; 0];

%
% Define the measurement-sensitivity matrix.

C = [1 -1 0];

%
% Define the observation-innovation matrix.

D = 0.1;

%
% Specify the state-space model using dssm. Identify the type of initial state distributions (StateType) by noting the following:
% x_{1,t} is an AR(2) process with diffuse initial distribution.
% x_{2,t} is the same AR(2) process as x_{1,t}.
% x_{3,t} is the constant 1 for all periods.

StateType = [2 2 1];
Mdl = dssm(A,B,C,D,'StateType',StateType);

% Mdl is a dssm model.
%
% Verify the diffuse state-space model using disp.

disp(Mdl)

% Cov0 has infinite variance for the AR(2) states.
% Copyright 2015 The MathWorks, Inc.