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

  1. function eta=fixpar(etaold,mat1,arg1,fixpar)
  2. %FIXPAR    Fixes parameters in state-space and ARX model structures
  3. %
  4. %    TH = fixpar(TH_OLD,MATRIX,ELEMENTS,PARAMETERVALUES)
  5. %
  6. %    TH : The new theta-matrix
  7. %    TH_OLD: The old theta-matrix
  8. %    MATRIX: What matrix to manipulate (one of 'A','B','C','D','K' or 'X0')
  9. %    ELEMENTS: Which elements to manipulate; an n by 2 matrix, where    each 
  10. %    row contains the row- and column numbers of the elements in question.
  11. %    PARAMETERVALUES: The values of the new, fixed parameters;a vector with
  12. %    n entries. If this argument is omitted, the parameters will be fixed to
  13. %    the values of the current estimates in TH_OLD.
  14. %       If MATRIX is given the value 'A1', 'A2', etc or 'B0', 'B1' etc
  15. %    the manipulations will be obtained in the corresponding matrix
  16. %    in an ARX-structure, provided TH_OLD is defined as such.
  17. %
  18. %    Example: th1 = fixpar(th,'A',[3,1;2,2;1,3])
  19. %
  20. %    Note: FIXPAR works only on standard model structures originally 
  21. %    defined    by MS2TH, ARX2TH or ARX; if ETAOLD is based on a user-
  22. %    defined    structure, you could obtain the same result with THINIT and by
  23. %    using the 3rd argument in PEM.
  24.  
  25. %    L. Ljung 10-4-90,11-02-91
  26. %    Copyright (c) 1990 by the MathWorks, Inc.
  27. %    All Rights Reserved.
  28.  
  29. if nargin<4,fixpar='d'; deff=1;end
  30.  
  31. if ~isthss(etaold) ,[a,b,c,d,f,lam]=th2poly(etaold);[nu,nf]=size(f);
  32. if max([nf length(c) length(d)])==1, etaold=arx2th(a,b,1,1,lam,etaold(1,2));
  33. else
  34. error('This routine is meaningful only for standard state-space structures (originally created by ms2th) and arx structures')
  35. end ,end
  36. if ~any(etaold(2,8)==[1 2 3]), 
  37. error('This routine is meaningful only for standard state-space structures (originally created by ms2th) and arx structures')
  38. end 
  39. [nr,nc]=size(etaold);
  40. nd=etaold(1,5);
  41. ms=getargth(etaold);[par,P,lambda]=th2par(etaold);
  42. [rms,cms]=size(ms);
  43.  
  44. if etaold(2,8)==3,arx=1;else arx=0;end
  45. if etaold(2,8)==1,cd='c';else cd='d';end
  46. T=etaold(1,2);
  47. if T>0 & etaold(2,8)==1, 
  48. error('This structure is marked as discrete-time, while the underlying parametrization is continuous-time. Do thd2thc first!'),end
  49. if mat1(1)~='x' & mat1(1)~='X'
  50.   if length(mat1)>1 
  51.      if ~arx
  52.     error('This option can be used only for ARX-models')
  53.      end
  54.      etapar=etaold(3,1:nd);
  55.      arg=getargth(etaold);
  56.      [rarg,carg]=size(arg);
  57.      as1=arg(:,1:rarg);
  58.      nr=find(sum(as1')==0);
  59.      [as,bs,cs,ds]=ssmodx9(etapar,-1,arg);
  60.      [ny,nz]=size(cs);[nx,nz]=size(as);[nz,nu]=size(bs);
  61.      na=(nr(1)-1)/ny;
  62.      if nu>0,nb=(nx-na*ny)/nu;else nb=0;end  
  63.      
  64.      mnr=eval(mat1(2:length(mat1)));
  65.      if mat1(1)=='a' | mat1(1)=='A'
  66.         if mnr>na, error('Matrix number exceeds model order!'),end
  67.      mat1='a'; arg1(:,2)=arg1(:,2)+(mnr-1)*ny;if ~deff,fixpar=-fixpar;end
  68.      end
  69.      if mat1(1)=='b' | mat1(1)=='B'    
  70.         if mnr>nb, error('Matrix number exceeds model order!'),end
  71.         if mnr==0, mat1='b'; 
  72.         else mat1='a';arg1(:,2)=arg1(:,2)+na*ny+(mnr-1)*nu;
  73.         end
  74.     if na==0,if mnr==0,mat1='d';else mat1='c';
  75.     arg1(:,2)=arg1(:,2)+(mnr-1)*nu;end,end
  76.      end
  77.    end
  78. end 
  79.  
  80. [ms,par]=fixxx(ms,par,mat1,arg1,fixpar);
  81. [rms,cms]=size(ms);if arx,ms(1,cms)=-ms(1,cms);end
  82.  
  83. eta=ms2th(ms,cd,par,lambda,abs(T));
  84. eta(2,7)=25;
  85. if arx, eta(2,8)=3;eta(2,7)=35;end