%IVXMV Estimates (multivariate) ARX-models using instrumental variables
%
% TH = ivxmv(Z,[NA NB NK],X)
%
% Z: The output-input data Z = [Y U] with the outputs Y
% and the inputs U arranged in column vectors
% [NA NB NK]: defines the model structure as follows:
% NA: an ny|ny matrix whose i-j entry is the order of the
% polynomial (in the delay operator) that relates the
% j:th output to the i:th output
% NB: an ny|nu matrix whose i-j entry is the order of the
% polynomial that related the j:th input to the i:th output
% NK: an ny|nu matrix whose i-j entry is the delay from
% the j:th input to the i:th output
% (ny: the number of outputs, nu: the number of inputs)
% X: The instrumental variables. Same format as Y.
%
% TH: the resulting model, given in the THETA-format (see HELP THETA)
%
% With TH=ivxmv(Z,[NA NB NK],X,MAXSIZE,T) some additional
% options can be achieved. See HELP AUXVAR for details
%
% L. Ljung 10-3-90
% Copyright (c) 1987-90 by the MathWorks, Inc.
% All Rights Reserved.
[nnr,nnc]=size(nn);
ny=nnr;nu=(nnc-ny)/2;
[Ncap,nz]=size(z);[Nc,nx]=size(x);
if nz>Ncap,error(' Data should be organized in column vectors!'),return,end
if Nc~=Ncap | nx~=ny, error('The matrix x shall have the same number of rows as z, and the number of columns must be equal to the number of outputs'),end
if nz~=(nu+ny),disp(' Incorrect number of orders specified!'),disp('For an AR-model nn=na'),disp('For an ARX-model, nn=[na nb nk]'),
error('see above'),return,end
na=nn(:,1:ny);
if nu>0,nb=nn(:,ny+1:ny+nu);else nb=zeros(ny,1);end
if nu>0,nk=nn(:,ny+nu+1:nnc);else nk=zeros(ny,1);end