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

  1. //--------------------------------------------------------------------------------
  2. //
  3. // dinitial
  4. //
  5. // Syntax: G=dinitial(a,b,c,d,x0,n)
  6. //
  7. // This routine plots the time response of the discrete linear system descried by,
  8. //
  9. //     x[n+1] = Ax[n] + Bu[n]
  10. //     y[n]   = Cx[n] + Du[n]
  11. //
  12. // to an initial condition on the states. The routine may be called in two ways:
  13. //
  14. // (1)  G=dinitial(A,B,C,D)
  15. //      (This produces the sequence with random initial conditions for
  16. //       a state-space model using the default 200 sample points).
  17. //
  18. // (2)  G=dinitial(A,B,C,D,X0)
  19. //      (This produces the sequence with initial conditions for
  20. //       a state-space model using the default 200 sample points).
  21. //
  22. // (3)  G=dinitial(A,B,C,D,X0,N)
  23. //      (This produces the sequence with initial conditions for
  24. //       a state-space model using the user specified number of sample
  25. //       points N).
  26. //
  27. // All 3 cases return the state and output responses. There are as
  28. // many columns in the output response (G.y) as there are outputs.
  29. // The state response matrix (G.x) has as many columns as there are
  30. // states.
  31. //
  32. // Note: Two matrices are returned in a list.
  33. //
  34. //       G.x = X values in the plot.
  35. //       G.y = Y values in the plot.
  36. //
  37. // Note: G.x has as many columns as there are states and N rows.
  38. //       G.y has as many columns as there are outputs and N rows.
  39. //
  40. // Note: The default number of sample points is 200.
  41. //
  42. // Copyright(C), by Jeffrey B. Layton, 1994
  43. // Version JBL 940912
  44. //--------------------------------------------------------------------------------
  45.  
  46. rfile abcdchk
  47. rfile dlsim
  48.  
  49. dinitial = function(a,b,c,d,x0,n)
  50. {
  51.    local(nargs,msg,estr,X0,N)
  52.  
  53. // Count number of input arguments
  54.    nargs=0;
  55.    if (exist(a)) {nargs=nargs+1;}
  56.    if (exist(b)) {nargs=nargs+1;}
  57.    if (exist(c)) {nargs=nargs+1;}
  58.    if (exist(d)) {nargs=nargs+1;}
  59.    if (exist(x0)) {nargs=nargs+1;}
  60.    if (exist(n)) {nargs=nargs+1;}
  61.  
  62. // Check number of arguments
  63.    if (nargs < 4) {
  64.        error("DINITIAL: Wrong number of input arguments.");
  65.    }
  66.  
  67. // Check A,B,C, and D for compatibility
  68.    msg="";
  69.    msg=abcdchk(a,b,c,d);
  70.    if (msg != "") {
  71.        estr="lsim: "+msg;
  72.        error(estr);
  73.    }
  74.  
  75. // Check is X0 is input
  76.    if (nargs == 4) {
  77.        X0=rand(a.nr,1);
  78.    else
  79.        X0=x0;
  80.        X0=X0[:];
  81.    }
  82.  
  83. // Check if n was input
  84.    if ( !exist(n) ) {
  85.        N=200;
  86.    else
  87.        N=n;
  88.    }
  89.  
  90. // Perform Simulation
  91.    Dum=dlsim(a,b,c,d,zeros(N,b.nc),X0[:]);
  92.    y=Dum.y;
  93.    x=Dum.x;
  94.  
  95.    return << x=x; y=y >>
  96. };
  97.