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

  1. function mod=modstruc(a,b,c,d,k,x0)
  2. %MODSTRUC  Constructs model structures to be used in MS2TH
  3. %
  4. %    MS = modstruc(A,B,C,D,K,X0)
  5. %
  6. %    MS = The resulting model structure.
  7. %    A,B,C,D,K,X0 are the matrices of the state space model
  8. %    
  9. %    xnew = A x(t) + B u(t) + K e(t)
  10. %    y(t) = C x(t) + D u(t) + e(t)
  11. %
  12. %    where xnew is x(t+T) or dx(t)/dt. X0 is the initial state.
  13. %
  14. %    The entries of these matrices are numerical values for the parameters 
  15. %    that are fixed, while a parameter to be    estimated (a free parameter) is
  16. %    entered as NaN in the corresponding position.
  17. %    Example: A=[0 1;NaN NaN].
  18. %    The default value of X0 is zeros.    
  19. %    See also CANFORM
  20.  
  21. %    L. Ljung 10-2-90,5-5-92
  22. %    Copyright (c) 1990 by the MathWorks, Inc.
  23. %    All Rights Reserved.
  24.  
  25. if nargin<5,error('All of the matrices A, B, C, D, K, must be specified!'),end
  26. [nx,nd]=size(a);
  27. if nx ~= nd, error('The A-matrix must be square!'),end
  28. if nargin<6, x0=zeros(nx,1);end,if isempty(x0),x0=zeros(nx,1);end
  29. [nd,nu]=size(b);
  30. if nx ~= nd & nu~=0, error('A and B must have the same number of rows!'),
  31. end
  32. [ny,nd]=size(c);
  33. if nx ~= nd, error('A and C must have the same number of columns!'),
  34. end
  35. [nd1,nd2]=size(d);
  36. if nd1 ~= ny & nu~=0, error('D and C must have the same number of rows!'),end
  37. if nd2 ~= nu, error('D and B must have the same number of columns!'),
  38. end
  39. [nd1,nd2]=size(k);
  40. if nd1 ~= nx, error('K and A must have the same numb er of rows!'),
  41. end
  42. if nd2 ~= ny, error('The number of columns in K must equal the number of coulumns in C!'),end
  43. [nd1,nd2]=size(x0);
  44. if nd1~=nx, error('X0 and A must have the same number of rows!'),end
  45. if nd2 ~= 1, error('X0 must be a coulmn vector!'),end
  46. mod(1:nx,1:nx)=a;
  47. if nu>0, mod(1:nx,nx+1:nx+nu)=b;end
  48. mod(1:nx,nx+nu+1:nx+nu+ny)=c';
  49. if nu>0, mod(1:ny,nx+nu+ny+1:nx+2*nu+ny)=d;end
  50. nn=nx+2*(nu+ny);
  51. mod(1:nx,nx+2*nu+ny+1:nn)=k;
  52. mod(1:nx,nn+1:nn+1)=x0;
  53. mod(1,nn+2)=ny;mod(2,nn+2)=nx;
  54.  
  55.