home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / languages / rlab1_23a / CTB / c2d < prev    next >
Text File  |  1995-11-14  |  2KB  |  70 lines

  1. //-----------------------------------------------------------------------------
  2. //
  3. // c2d
  4. //
  5. // Syntax: G=c2d(A,B,T)
  6. //
  7. // This routine converts a continuous time system given by:
  8. //      .
  9. //      x = Ax + Bu
  10. //
  11. // to the discrete time state space system:
  12. //
  13. //      x[n+1] = phi * x[n] + gamma * u[n]
  14. //
  15. // It assumes that there is a zero-hold on the inputs and that
  16. // it has a sampling time of T.
  17. //
  18. // The results are returned in a list:
  19. //
  20. //      G.phi = phi
  21. //      G.gamma = gamma
  22. //
  23. // Ref:  Frankin, G. F., Powell, J. D., Workman, M. L., "Digital Control of
  24. //       Dynamic Systems," Addison-Wesley, Reading Mass., 1990.
  25. //
  26. // Note: This zero order hold conversion was just taken from the ref.
  27. //       as a special case of the first order hold with triangle
  28. //       approximation.
  29. //
  30. // Copyright (C), by Jeffrey B. Layton, 1994
  31. // Version JBL 940918
  32. //-----------------------------------------------------------------------------
  33.  
  34. rfile abcdchk
  35. rfile expm
  36.  
  37. c2d = function(A,B,T)
  38. {
  39.    local(nargs,msg,estr,FT,E,phi,gamma)
  40.  
  41. // Count number of input arguments
  42.    nargs=0;
  43.    if (exist(A)) {nargs=nargs+1;}
  44.    if (exist(B)) {nargs=nargs+1;}
  45.    if (exist(T)) {nargs=nargs+1;}
  46.  
  47.    if (nargs < 3) {
  48.        error("C2D: Wrong number of Input arguments.");
  49.    }
  50.  
  51. // Check A,B to ensure that it is correct
  52.    msg="";
  53.    msg=abcdchk(A,B);
  54.    if (msg != "") {
  55.        estr="C2D: "+msg;
  56.        error(estr);
  57.    }
  58.  
  59. // Form FT matrix and take matrix exponential
  60.    FT=[       A,                B;
  61.        zeros(B.nc,A.nr), zeros(B.nc,B.nc)];
  62.    E=expm(FT*T);
  63.  
  64. // Find Phi and Gamma partitions of E
  65.    phi=E[1:A.nr;1:A.nr];
  66.    gamma=E[1:A.nr;(A.nr+1):(A.nr+B.nc)];
  67.  
  68.    return << phi=phi; gamma=gamma >>
  69. };
  70.