% DEMO_GPCMP2.M
% Example of how to solve the Diophantine equations and obtain
% the Prediction Model (PM) used by the GPC method.
clear all

iex=1;
iex=dread('Example number:',iex);
if iex == 1
a1=-0.8; b0=0.4; b1=0.6;
A=[1 a1];    % The polynomial A=a0 + a1z^{-1}
B=[b0 b1];   % The polynomial B=b0 + b1z^{-1}

a=[0,1;0,-a1]; b=[b0;b1-a1*b0]; d=[1,0]; e=0;

elseif iex ==2
   a=[1.5 1;-0.7 0]; b=[2;-1.3]; d=[1,0]; e=0;
   [B,A]=ss2tf(a,b,d,e);
   B=B(2:3);
end

L=4;

%%% Use polynomial approach as in GPC
[Fgpc,Puy,G,F,E]=poly2gpcpm(A,B,L)

%%% Use state space approach as in Dycops5 papaer.
L=L; J=2;
[At,Bt,Atmin,Btmin,o,Hd] = ss2essm(a,b,d,e,L,J,0);
[Fempc,Pempc,sAt] = htilde2(At,Bt,L)
