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

  1. //---------------------------------------------------------------------------
  2. //
  3. // ltitr
  4. //
  5. // Syntax: X=ltitr(A,B,U,X0)
  6. //
  7. // This routine computes the time response of the following system:
  8. //
  9. //  x[n+1] = Ax[n] + Bu[n]
  10. //
  11. // to the input U. The result is returned in a matrix X which has as
  12. // many columns as there are outputs y (and with length(U) rows).
  13. //
  14. // This routine can also be used with initial conditions as:
  15. //
  16. //  X=ltitr(A,B,U,X0)
  17. //
  18. // Note: The input U must have as many columns as there are inputs u
  19. // in the system. Each row of U corresponds to a new time point.
  20. //
  21. // Ref: Mathworks, "Control System Toolbox User's Guide," 1992.
  22. //
  23. // Copyright (C), by Jeffrey B. Layton, 1994
  24. // Version JBL 940914
  25. //---------------------------------------------------------------------------
  26.  
  27. ltitr = function(a,b,u,x0)
  28. {
  29.    local(n,nargs,U,X0,i,x)
  30.  
  31. // Check number of input arguments
  32.    nargs=0;
  33.    if (exist(a)) {nargs=nargs+1;}
  34.    if (exist(b)) {nargs=nargs+1;}
  35.    if (exist(u)) {nargs=nargs+1;}
  36.    if (exist(x0)) {nargs=nargs+1;}
  37.  
  38.    U=u.';
  39.  
  40. // Get problem dimensions
  41.    n=U.nc;
  42.  
  43. // Initialize x to the correct size
  44.    x[a.nr;n]=0;
  45.  
  46. // Check to see if x0 was input. If it wasn't make x0, zero.
  47.    if (nargs == 3) {
  48.        X0=zeros(a.nr,1);
  49.    else
  50.        X0=x0;
  51.    }
  52.  
  53. // Start computing
  54.    if (nargs == 4) {
  55.        X0=X0[:];
  56.    }
  57.    X0=X0[:];
  58.    for (i in 1:n) {
  59.         x[;i]=X0;
  60.         X0=a*X0+b*U[;i];
  61.    }
  62.    x=x.';
  63.  
  64.    return x
  65. };
  66.