% ***************************************************************************
% COPYRIGHT BY T.E. MARLIN 1995
% FILNAME : DMC_DES.M
% Version 2.0
% LAST UPDATED : MAY 1995
% DISCRIPTION OF FILE :
% THIS M-FILE CALCULATES THE DMC CONTROL MATRIX
% AND THE TWO VECTORS USED FOR THE CONTROL CALCULATION
% AT EACH INTERATION FOR THE 2X2 SYSTEM
% ***************************************************************************

%  ************************************************************************
%  ****************   PERFORM THE MATRIX CALCULATIONS  ********************
%  form the complete model matrix by combining individual input-output

A = [ A11 A12 ; A21 A22 ];

ATRAN = A' ;

%  form the output weighting matrix with the same values for each
%  time step and no interaction weights

W11 = W1*eye(NN) ; W22 = W2*eye(NN); W12 = zeros (NN); W21 = zeros (NN);

WW  = [ W11 W12 ; W21 W22 ] ;

APROD = A' * WW * A ;

%  form the input weighting matrix with the same values for each step

Q11 = Q1*eye(MM) ; Q22 = Q2*eye(MM); Q12 = zeros (MM); Q21 = zeros (MM);
QQ  = [ Q11 Q12 ; Q21 Q22] ;

%  complete the calculations, 

AAUG  = APROD + QQ  ;

AAUGINV = inv (AAUG);

%   *************************************************************
%   ***************   the DMC  controller matrix  ***************

DMCCON  =  AAUGINV * ATRAN * WW ;

%   ***************** the vector values for implementation  *****
%           each vector is for an individual manipulated variable 

DMC_V1 = DMCCON(1,:)    ;

DMC_V2 = DMCCON(1+MM,:) ;

%clear A; clear ATRAN; clear WW ;
%pack

