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

  1. function eta=mf2th(model,cd,parval,aux,lambda,T)
  2. %MF2TH  Packages user defined model structures into the THETA model format
  3. %
  4. %    TH = mf2th(MODEL,CD,PARVAL,AUX,LAMBDA,T)
  5. %
  6. %    TH: The resulting model matrix
  7. %
  8. %    MODEL: The model structure specified as    the name of a user-written 
  9. %    m-file, which should have the format
  10. %
  11. %        [a,b,c,d,k,x0]=username(parameters,T,AUX)
  12. %
  13. %    Then MODEL='username'. See HELP SSMODEL for the format.
  14. %    CD: CD='c' if 'username' provides a continuous time model when called
  15. %    with a negative value of T. Else CD = 'd'.
  16. %    PARVAL: The values of the free parameters
  17. %    AUX:   The values of auxiliary parameters in the user-written m-file 
  18. %    above.
  19. %    LAMBDA: The covariance matrix of the innovations
  20. %    T: The sampling interval of the data (always a positive number)
  21. %    Default values: AUX=[]; T=1; LAMBDA=identity
  22.  
  23. %    L. Ljung 10-2-1990
  24. %    Copyrigth (c) 1990 by the MathWorks, Inc.
  25. %    All Rights Reserved.
  26.  
  27. if nargin<3,error('File name, cont/discrete, and parameters must be specified!'),end
  28.  
  29. if nargin<6, T=[];end
  30. if nargin<5, lambda=[];end
  31. if nargin<4, aux=[];end
  32. if isempty(T),T=1;end
  33. if isempty(aux),aux=0;end % This is due to a bug in feval (destroys results if
  34.                       % one argument is [])
  35. [prd,pcd]=size(parval);if prd>pcd,parval=parval';end;d=length(parval);
  36. if T<0,error('The sampling interval T must be a positive number. Use ''c'' in the second argument to indicate continuous time model!'),end
  37. [rarg,carg]=size(aux);
  38. if ~isstr(cd),error('The argument cd must be a string'),end
  39. if cd=='c',eta(1,2)=-T;else eta(1,2)=T;end
  40.  
  41. eta(1,6:7)=[rarg,carg];
  42. eta(1,8:7+length(model))=model;
  43. [a,b,c,Dd,k,x0]=feval(model,parval,T,aux);
  44. [nx,nx1]=size(a);[nx2,nu]=size(b);[ny,nx3]=size(c);[ny1,nu2]=size(Dd);
  45. [nx4,ny2]=size(k);[nx5,ett]=size(x0);
  46. if nu==0,nx2=nx;ny1=ny;end,
  47. if nx~=nx1,error('A-matrix in m-file must be square!'),end
  48. if nx~=nx2,error('The B-matrix in m-file must have the same number of rows as A'),end
  49. if nx~=nx3,error('The C-matrix in m-file must have the same number of columns as A!'),end
  50. if nx~=nx4,error('The K-matrix in m-file must have the same number of rows as A!');end
  51. if nx~=nx5,error('Incorrect size of initial value vector!'),end
  52. if ett~=1,error('X0 must be column vector!'),end
  53. if nu~=nu2,error('D-matrix in m-file must have same number of columns as B!'),end
  54. if ny~=ny1,error('D-matrix in m-file must have same number of rows as C!'),end
  55. if ny~=ny2,error('K-matrix in m-file must have same number of columns as C has rows!'),end
  56.  
  57. if max(abs(eig(a-k*c)))>1+10*eps,disp('WARNING: Predictor unstable!'),end
  58. if isempty(lambda),lambda=eye(ny);end
  59. eta(1,1)=det(lambda);eta(1,[3:5])=[nu ny d];
  60.  
  61. ti=fix(clock);
  62. ti(1)=ti(1)/100;
  63. eta(2,1)=d;
  64. eta(2,2:6)=ti(1:5);
  65. eta(2,7)=22;
  66. if cd=='c',eta(2,8)=5;else eta(2,8)=4;end
  67. eta(3,1:d)=parval;
  68. %eta(4:3+d,1:d)=zeros(d,d);
  69. eta(4+d:3+d+rarg,1:carg)=aux;
  70. eta(4+d+rarg:3+ny+d+rarg,1:ny)=lambda;
  71.  
  72.  
  73.