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

  1. function [A,B,C,D,K,X0]=ssmodx9(th,T,mod)
  2. %SSMODX9 The standard state-space model
  3. %
  4. %    [A,B,C,D,K,X0] = ssmodx9(PARVAL,T,MS)
  5. %
  6. %    This routine is used as the standard model-defining routine
  7. %    inside the THETA-structure for state space models if no user-
  8. %    defined structure is specified. The use of SSMODx9 should be
  9. %    transparent to the user.
  10. %
  11. %    A,B etc: The discrete time state space matrices corresponding to
  12. %    the parameter values PARVAL for a linear model structure
  13. %    defined by MS (obtained from MODSTRUC or CANFORM)
  14.  
  15. %    L. Ljung 10-2-90,5-5-92
  16. %    Copyright (c) 1990 by the MathWorks, Inc.
  17. %    All Rights Reserved.
  18.     
  19. [nx,nn]=size(mod);nyy=mod(1,nn);nx=mod(2,nn);
  20. ny=abs(nyy);nu=(nn-nx-2*ny-2)/2;
  21. s=1;
  22. if nyy<0,arx=1;else arx=0;end
  23. na=0;
  24. if arx,
  25. as1=mod(1:nx,1:nx);
  26. nr=find(sum(as1')==0);
  27. if isempty(nr),na=nx/ny;else na=(nr(1)-1)/ny;end
  28. end
  29. A=mod(1:nx,1:nx);
  30. for kr=1:nx
  31.     for kc=1:nx
  32.     if isnan(A(kr,kc)), A(kr,kc)=th(s);s=s+1;end
  33.     end
  34. end
  35. B=mod(1:nx,nx+1:nx+nu);
  36. for kr=1:nx
  37.     for kc=1:nu
  38.     if isnan(B(kr,kc)),B(kr,kc)=th(s);s=s+1;end
  39.     end
  40. end
  41. if na==0
  42. C=mod(1:nx,nx+nu+1:nx+nu+ny)';
  43. for kr=1:ny
  44.     for kc=1:nx
  45.     if isnan(C(kr,kc)),C(kr,kc)=th(s);s=s+1;end
  46.     end
  47. end
  48. D=mod(1:ny,nx+nu+ny+1:nx+2*nu+ny);
  49. for kr=1:ny
  50.     for kc=1:nu
  51.     if isnan(D(kr,kc)),D(kr,kc)=th(s);s=s+1;end
  52.     end
  53. end
  54. else
  55. C=A(1:ny,1:nx);
  56. if nu>0,D=B(1:ny,:);else D=[];end
  57. end
  58. K=mod(1:nx,nx+2*nu+ny+1:nx+2*nu+2*ny);
  59. for kr=1:nx
  60.     for kc=1:ny
  61.     if isnan(K(kr,kc)),K(kr,kc)=th(s);s=s+1;end
  62.     end
  63. end
  64.  
  65. X0=mod(1:nx,nx+2*nu+2*ny+1);
  66. for kr=1:nx
  67.     if isnan(X0(kr)),X0(kr)=th(s);s=s+1;end
  68. end
  69. if T>0 % We shall in this case sample the model with sampling interval T
  70. s = expm([[A [B K]]*T; zeros(nu+ny,nx+nu+ny)]);
  71. A = s(1:nx,1:nx);
  72. B = s(1:nx,nx+1:nx+nu);
  73. K = s(1:nx,nx+nu+1:nx+nu+ny);
  74. end
  75.  
  76.