  function ymod = dimcmod(modnum,modden,ymodvec,umodvec)
% 
% 18 Sept 13 - BWB -- used in hw3 solution
% calculates the next model output, given previous model
%   outputs and plant inputs
%   ymod(z) = gpmod(z)u(z)
%
% the model transfer function has the form
%               model numberator polynomial coefficients 
%   gpmod =     ------------
%               model denominator polynomial coefficients
%
% the model output prediction has the form of
%   ymod(k+1) = modden(2)*ymod(k) + modden(3)*ymod(k-1) + ...
%               + modnum(1)*u(k) + modnum(2)*u(k-1) + ...
% where 
%       modden(i) is a model denominator coefficient; 
%          note that modden(1) is assumed to be 1
%       modnum(i) is a model numerator coefficient
%
% in our case, however, ymodvec is passed in as
%   [... ymodvec(k-2) ymodvec(k-1) ymodvec(k)]
% also, umodvec is passed in as
%   [... umodvec(k-2) umodvec(k-1) umodvec(k)]
% so that we need to "reorient" the model output and input vectors for a
% proper multiplication
  ymod = -modden(2:length(modden))*ymodvec(length(modden)-1:-1:1) + modnum*umodvec(length(modnum):-1:1);
% note that ymod is passed back as a scalar (becoming ymodvec(k+1) in the
% when returned to the calling file