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

  1. function [e,v,w,a,b,c,d,f]=pe(z,th)
  2. %PE    Computes prediction errors.
  3. %
  4. %    E = pe(Z,TH)
  5. %
  6. %    E : The prediction errors
  7. %    Z : The output-input data Z=[y u]
  8. %    TH: The model. Format as in HELP THETA
  9. %
  10. %    A more complete set of information associated with the model TH and the
  11. %    data Z is obtained by
  12. %
  13. %    [E,V,W,A,B,C,D,F]=pe(Z,TH)
  14. %
  15. %    Here A,B,C,D,and F are the polynomials associated with TH and
  16. %    W = B/F u and V = A[y - W].
  17.  
  18. %    L. Ljung 10-1-86,2-11-91
  19. %    Copyright (c) 1986-90 by the MathWorks, Inc.
  20. %    All Rights Reserved.
  21.  
  22. [Ncap,nz]=size(z);
  23. nu=th(1,3);
  24. if isthss(th),
  25. [nr,nc]=size(th);
  26. nd=th(1,5);
  27. sspmod=getmfth(th);
  28.  
  29. [etapar,P,lambda]=th2par(th);
  30. arg=getargth(th);
  31. T=th(1,2);
  32. if any(th(2,8)==[2 3]),Tmod=-1;else Tmod=abs(T);end
  33. if length(etapar)==0,etapar=0;end
  34. [a,b,c,d,k,x0]=feval(sspmod,etapar,Tmod,arg);
  35. [ny,nx]=size(c);
  36. if nu+ny~=nz, error('Incorrect number of data columns specified! Should be equal to the sum of the number of inputs and the number of outputs'),end 
  37. x=ltitr(a-k*c,[k b-k*d],z,x0);
  38. e=z(:,1:th(1,4))-(c*x')';
  39.    if ~isempty(d),e=e-(d*z(:,th(1,4)+1:th(1,4)+th(1,3))')';end
  40. else
  41.  
  42. if nu~=nz-1,error('Incorrect number of data columns specified! Should be equal to the sum of the number of inputs and the number of outputs'),end 
  43.  
  44. [a,b,c,d,f]=th2poly(th);[nu,nb]=size(b);[nu,nf]=size(f);
  45. nc=length(c);nd=length(d);
  46. ni=max([length(a)+nd-2 nb+nd-2 nf+nc-2 1]);
  47. v=filter(a,1,z(:,1));
  48. for k=1:nu, w(:,k)=filter(b(k,:),f(k,:),z(:,k+1));v=v-w(:,k);end
  49. e=pefilt(d,c,v,zeros(1,ni));
  50. end
  51.