function [Matricesf Matricesr] = matrices_analyze_dro(nfull,nred,N,x0if,x0ir)

%% System Model
alpha = 0;
d0m = [0;0];
% N = 8; 
% number of inputs
nu = 2;
[Gfull] = model_baltrunc(nfull);
[Gred Tl Tr] = baltrunc(Gfull,nred);
% make a discrete-time approximation
Ts	= 1;
Gfull = c2d(Gfull,Ts);
Gred = c2d(Gred,Ts);
[Af Bf Cf Bdf] = deal(Gfull.a,Gfull.b(:,1:nu),Gfull.c,Gfull.b(:,nu+1:end));
[Ar Br Cr Bdr] = deal(Gred.a,Gred.b(:,1:nu),Gred.c,Gred.b(:,nu+1:end));	
% number of states
nx = size(Gfull.a, 2);
x0f = x0if; 
x0r = Tl*x0ir;
% number of outputs
ny = size(Gfull.c, 1);
nyr = size(Gred.c, 1);
% weight matrices
clear diag

Q = Cf'*eye(ny)*Cf;
R = diag(ones(nu,1),0);
Qr = Cr'*eye(nyr)*Cr;
Rr = diag(ones(nu,1),0);

umax = 1;
umin = -1;

%% define matrices for MPC
% 1: full controller
% X,Y,Z,QQ,RR
[Xf,Yf,Zf]=xyfun(N,Af,Bf,Bdf);
[QQ,RR]=QRfun(Q,R,N);
% Matrixes for quadprog
Fxf = Zf'*QQ*Yf;
Fdf = Xf'*QQ*Yf;
Ff = Fdf'*d0m + Fxf'*x0f;
Hf = (Yf'*QQ*Yf)+RR;
Gf = [eye(nu*N);-1*eye(nu*N)];
Wf = [umax*ones(nu*N,1);-umin*ones(nu*N,1)];

% 2: reduced controller
% X,Y,Z,QQ,RR
[Xr,Yr,Zr]=xyfun(N,Ar,Br,Bdr);
[QQr,RRr]=QRfun(Qr,Rr,N);
% Matrixes for quadprog
Fxr = Zr'*QQr*Yr;
Fdr = Xr'*QQr*Yr;
Fr = Fdr'*d0m + Fxr'*x0r;
Hr = (Yr'*QQr*Yr)+RRr;
Gr = [eye(nu*N);-1*eye(nu*N)];
Wr = [umax*ones(nu*N,1);-umin*ones(nu*N,1)];

Matricesf.H = Hf;
Matricesf.F = Ff;
Matricesf.W = Wf;
Matricesf.G = Gf;

Matricesr.H = Hr;
Matricesr.F = Fr;
Matricesr.W = Wr;
Matricesr.G = Gr;

