home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / r / rlab / CTB / simdata < prev    next >
Encoding:
Text File  |  1995-11-15  |  1004 b   |  50 lines

  1. //-----------------------------------------------------------------------
  2. //
  3. // simdata
  4. //
  5. // Syntax:  Y=simdata(A,B,C,D,n)
  6. //
  7. // This routine forms the ERA data matrix Y from successive
  8. // simulations of length n samples to the system
  9. // 
  10. //  x[k+1] = Ax[k] + Bu[k]
  11. //    y[k] = Cx[k] + Du[k]
  12. // 
  13. // Originally written by Lee D. Peterson
  14. // Modified and ported to RLaB by Jeffrey B. Layton
  15. // Version JBL 940919
  16. //-----------------------------------------------------------------------
  17.  
  18. rfile abcdchk
  19.  
  20. simdata = function(A,B,C,D,n)
  21. {
  22.    local(l,m,Y,akm1,ptr,estr,msg,k)
  23.  
  24. // See if A,B,C, and D are compatible.
  25.    msg="";
  26.    msg=abcdchk(A,B,C,D);
  27.    if (msg != "") {
  28.        estr="SIMDATA: "+msg;
  29.        error(estr);
  30.    }
  31.  
  32. // Get problem dimensions
  33.    l=C.nr;
  34.    m=B.nc;
  35.    Y=zeros(n*l,m);
  36.  
  37. //
  38. // Form each Markov parameter and stuff it into Y
  39. //
  40.    Y[1:l;]=D;
  41.    Y[l+1:l+l;]=C*B;
  42.    akm1=B;
  43.    for (k in 2:n-1) {
  44.         akm1=A*akm1;
  45.         ptr=k*l;
  46.         Y[ptr+1:ptr+l;]=C*akm1;
  47.    }
  48.    return Y;
  49. };
  50.