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

  1. //--------------------------------------------------------------------------
  2. //
  3. // dcgain
  4. //
  5. // Syntax: k=dcgain(a,b,c,d)
  6. //
  7. //
  8. // This routine finds the D.C. gain (or low frequency gain) of a continuous
  9. // system. Calling the routine as,
  10. //
  11. //     k=dcgain(a,b,c,d)
  12. //
  13. // computes the steady-state gain of the continuous state-space system.
  14. //
  15. // Calling the routine as,
  16. //
  17. //    k=dcgain(num,den)
  18. //
  19. // computes the steady-state gain of the continuous polynomial transfer
  20. // function system,
  21. //
  22. //    G(s)= num(s)/den(s)
  23. //
  24. // where num contains the numerator polynomial coefficients and den
  25. // contains the denominator polynomial coefficients in descending order.
  26. //
  27. // Copyright (C), by Jeffrey B. Layton, 1994
  28. // Version JBL 940917
  29. //--------------------------------------------------------------------------
  30.  
  31. rfile abcdchk
  32. rfile tfchk
  33.  
  34. dcgain = function(a,b,c,d)
  35. {
  36.    local(nargs,A,num,den,msg,estr,k)
  37.  
  38. // Count number of input arguments
  39.    nargs=0;
  40.    if (exist(a)) {nargs=nargs+1;}
  41.    if (exist(b)) {nargs=nargs+1;}
  42.    if (exist(c)) {nargs=nargs+1;}
  43.    if (exist(d)) {nargs=nargs+1;}
  44.  
  45. // Transfer Function Representation
  46.    if (nargs == 2) {
  47.        A=tfchk(a,b);
  48.        num=A.numc;
  49.        den=A.denc;
  50.        if ( (length(den) == 0) || (length(num) == 0) ) {
  51.            k=[];
  52.        else
  53.            k=num[;length(den)]/den[length(den)];
  54.        }
  55.  
  56. // State-Space Representation
  57.    else if (nargs == 4) { 
  58.        msg="";
  59.        msg=abcdchk(a,b,c,d);
  60.        if (msg != "") {
  61.            estr="DCGAIN: "+msg;
  62.            error(estr);
  63.        }
  64.        k=-c/a*b+d;
  65.    else
  66.        error("dcgain: Wrong Number of Input Arguments.");
  67.    }}
  68.  
  69.    return k
  70. };
  71.