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

  1. function theta=ms2th(ms,cd,parval,lambda,T)
  2. %MS2TH  Packages standard state-space parameterizations into the THETA format
  3. %
  4. %    THETA = ms2th(MS,CD,PARVAL,LAMBDA,T)
  5. %
  6. %    THETA: The resulting matrix in the THETA format (See help theta)
  7. %
  8. %    MS: The model structure. Specifies which state space matrix coeff-
  9. %     icients that are free and which are fixed (Generated by MODSTRUC or 
  10. %    CANFORM)
  11. %
  12. %    CD: CD='c' means a continuous-time model. CD='d' denotes a discrete 
  13. %    time model (default CD='d')
  14. %
  15. %    PARVAL: The values of the free parameters (Default zeros)
  16. %    LAMBDA: The covariance matrix of the innovations (Default Identity)
  17. %    T: The sampling interval (Default 1). For continuous time models this
  18. %    is the sampling interval of the data to be used for the fit in pem.
  19. %    See also MF2TH, ARX2TH
  20.  
  21. %    L. Ljung 10-2-1990,4-7-92
  22. %    Copyright (c) 1990 by the MathWorks, Inc.
  23. %    All Rights Reserved.
  24.  
  25. if nargin<5, T=[];end
  26. if nargin<4, lambda=[];end
  27. if nargin<3, parval=[];end 
  28. if nargin<2, cd=[];end
  29. if isempty(T),T=1;end
  30. d1=sum(sum(isnan(ms))');
  31. if isempty(parval),parval=zeros(1,d1);end
  32. if isempty(cd), cd='d';end, cd=cd(1);
  33. if cd~='c' & cd~='d', 
  34.   error('CD must be one of ''c''(ontinuous) or ''d''(iscrete)')
  35. end
  36. [nx,nn]=size(ms);nyy=ms(1,nn);
  37. if nyy<0,arx=1;else arx=0;end
  38. d=length(parval);
  39. if d~=d1 & ~arx, 
  40.   error('Incorrect number of parameter values  have been specified; must be equal to the number of ''NaN'':s in the model structure!')
  41. end
  42.  
  43. if T<0,
  44.   error('The sampling interval T must be a positive number. Use ''c'' in the second argument to indicate continuous time model!')
  45. end
  46.  
  47. [rarg,carg]=size(ms);
  48. if cd=='c',theta(1,2)=-abs(T);else theta(1,2)=abs(T);end
  49. if cd=='d',Tmod=-1;else Tmod=abs(T);end
  50. theta(1,6:7)=[rarg,carg];
  51.  
  52. [a,b,c,Dd,k,x0]=ssmodx9(parval,Tmod,ms);
  53.  
  54. if ms(1,carg)>0,
  55.    if max(abs(eig(a-k*c)))>1,disp('WARNING: Predictor unstable!'),end
  56. end
  57. [ny,nx]=size(c);[nx,nu]=size(b);
  58. if isempty(lambda),lambda=eye(ny);end
  59. theta(1,1)=det(lambda);
  60. ti=fix(clock);
  61. ti(1)=ti(1)/100;
  62. theta(1,3:5)=[nu ny d];theta(2,1)=theta(1,1);
  63. theta(2,2:6)=ti(1:5);
  64. theta(2,7)=21;
  65. if cd=='c', theta(2,8)=1;else theta(2,8)=2;end
  66. if d>0,
  67.     theta(3,1:d)=parval;
  68. end
  69. theta(4+d:3+d+rarg,1:carg)=ms;
  70. theta(4+d+rarg:3+ny+d+rarg,1:ny)=lambda;
  71.  
  72.