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

  1. //------------------------------------------------------------------------------
  2. //
  3. // ss2tf
  4. //
  5. // Syntax: A=ss2tf(a,b,c,d,Inp)
  6. //
  7. // This routine converts a state-space model to a transfer function model.
  8. // It creates the transfer function:
  9. //
  10. //             num(s)          -1
  11. //     H(s) = -------- = C(sI-A) B + D
  12. //             den(s)
  13. //
  14. // of the system:
  15. //     .
  16. //     x = Ax + Bu
  17. //     y = Cx + Du
  18. //
  19. // for the specified input Inp (optional input). The vector den contains
  20. // the coefficients of the denominator in descending powers of s. The
  21. // numerator coefficients are returned in the vector num. All transfer
  22. // functions for all outputs will be returned with each row of num
  23. // containing the numerator for the transfer function.
  24. //
  25. // The results are returned in a list:
  26. //    A.num = numerator
  27. //    A.den = denominator
  28. //
  29. // Copyright (C), by Jeffrey B. Layton, 1994
  30. // Version JBL 940919
  31. //------------------------------------------------------------------------------
  32.  
  33. rfile abcdchk
  34. rfile poly
  35.  
  36. ss2tf = function(a,b,c,d,Inp)
  37. {
  38.    local(msg,estr,b,d,i,num,den)
  39.  
  40. // Check state space system.
  41.    msg="";
  42.    msg=abcdchk(a,b,c,d);
  43.    if (msg != "") {
  44.        estr="SS2TF: "+msg;
  45.        error(estr);
  46.    }
  47.  
  48. // error Cheking on Inp
  49.    if (exist(Inp)) {
  50.        if (Inp > b.nc) {
  51.            error("SS2TF: Inp > number of inputs.");
  52.        }
  53.        b=b[;Inp];
  54.        d=d[;Inp];
  55.    else
  56.        if (b.nc > 1) {
  57.            error("SS2TF: Inp must be input for systems with more than 1 input.");
  58.        }
  59.    }
  60.  
  61. // Find Denominator
  62.    den=poly(a);
  63.  
  64. // Special Case: The input system (a,b,c,d) is just a simple gain
  65. //               or only has a denominator (don't need to find numerator).
  66.    if ( (isempty(b)) && (isempty(c)) ) {
  67.        num=d;
  68.        if ( (!isempty(d)) && (!isempty(a)) ) {
  69.             den=[];
  70.        }
  71.        return << num=num; den=den >>
  72.    }
  73.  
  74.    num = ones(d.nr,length(a)+1);
  75.    for (i in 1:d.nr) {
  76.         num[i;]=poly(a-b*c[i;])+(d[i]-1)*den;
  77.    }
  78.  
  79.    return << num=num; den=den >>
  80. };
  81.