home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l455 / 9.ddi / IDENT.DI$ / ARX2TH.M < prev    next >
Encoding:
Text File  |  1993-03-11  |  2.7 KB  |  76 lines

  1. function eta=arx2th(A,B,ny,nu,lam,Tsamp)
  2. %ARX2TH    constructs the THETA-format for an ARX model
  3. %
  4. %    th=arx2th(A,B,ny,nu)
  5. %
  6. %    A,B: The given matrix polynomials for a (possibly) multivariable
  7. %    ARX-model  
  8. %    y(t) + A1 y(t-1) + .. + An y(t-n) = 
  9. %    = B0 u(t) + ..+ B1 u(t-1) + .. Bm u(t-m)
  10. %    A = [I A1 A2 .. An],  B=[B0 B1 .. Bm]
  11. %    ny, nu : The number of outputs and inputs, respectively
  12. %
  13. %    TH is returned as a model structure (in the THETA-format, see HELP 
  14. %    theta)    where free parameters are consistent with the structure of A 
  15. %    and B, i.e. leading zeros in the rows of B are regarded as fixed 
  16. %    delays, and trailing zeros in the rows of A and B are regarded as a 
  17. %    definition of lower order polynomials. These zeros will thus be 
  18. %    regarded as fixed while all other parameters are free. The nominal 
  19. %    values of these free parameters are set equal to the values in A and B.
  20. %    With th = arx2th(A,B,ny,nu,LAMBDA,Tsamp) also the innovations covarian-
  21. %    ce matrix LAMBDA and the sampling interval Tsamp can be specified.
  22. %
  23. %    See also TH2ARX, and ARX
  24.  
  25. %        L. Ljung 10-2-90,11-2-91
  26. %        Copyright (c) 1986-90 by the MathWorks, Inc.
  27. %        All Rights Reserved.
  28.  
  29. if nargin<6, Tsamp=[];end, if nargin<5, lam=[];end
  30. if isempty(Tsamp),Tsamp=1;end, if isempty(lam),lam=eye(ny);end
  31. [ra,ca]=size(A);if isempty(B),rb=ra;nu=0;else [rb,cb]=size(B);end
  32. na=(ca-ny)/ny; if nu>0,nb=(cb-nu)/nu;else nb=0;end
  33. if ra~=ny | rb~=ny, error('The A and the B polynomials must have the same number of rows as the number of outputs!'),end
  34. if floor(na)~=na | floor(nb)~=nb,error('The size of A or B is not consistent with an ARX-model! The number of columns must be a multiple of the number of rows'),end
  35. for outp=1:ny
  36. for kk=1:ny
  37. sl=A(outp,ny+kk:ny:na*ny+ny);
  38. sl=(sl~=0);sl=sl(length(sl):-1:1);
  39. sl=cumsum(sl);ksl=max(find(sl==0));if length(ksl)==0,ksl=0;end
  40.  
  41. nna(outp,kk)=na-ksl;
  42. end
  43. for kk=1:nu
  44. sl=B(outp,kk:nu:nb*nu+nu);
  45. sl1=(sl~=0);ksl=max(find(cumsum(sl1)==0));
  46. if length(ksl)==0,ksl=0;end
  47. nnk(outp,kk)=ksl;
  48. sl1=sl1(length(sl1):-1:1);sl=cumsum(sl1);
  49. ksl=max(find(sl==0));if length(ksl)==0,ksl=0;end
  50. if ksl==nb+1,nnb(outp,kk)=0;nnk(outp,kk)=0;else
  51. nnb(outp,kk)=nb-ksl-nnk(outp,kk)+1;end
  52. end
  53. end
  54.  
  55. nn=[nna nnb nnk];
  56. nd=sum(sum(nna)')+sum(sum(nnb)');
  57. eta0=mketaarx(nn,ones(1,nd));
  58. [A1,B1]=th2arx(eta0);[ra,ca]=size(A1);[rb,cb]=size(B1);
  59. A1=A1(:,ny+1:ca);
  60. Am=A(:,ny+1:ca);
  61. B2=B1(:,nu+1:cb);Bm=B(:,nu+1:cb);
  62. C=[A1 B2];
  63. par=[];
  64. for kk=1:ny
  65. if ~isempty(Am),filla=-Am(kk,find(A1(kk,:)==-1));else filla=[];end
  66. if ~isempty(Bm),fillb=Bm(kk,find(B2(kk,:)==1));else fillb=[];end
  67. par=[par filla fillb];
  68. end
  69.  
  70. for kk=1:ny
  71. if nu>0,par=[par B(kk,find(B1(kk,1:nu)==1))];end
  72. end
  73. eta=mketaarx(nn,par,lam,Tsamp);
  74. eta(2,7)=32;
  75.  
  76.