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

  1. //-------------------------------------------------------------------
  2. //
  3. // append
  4. //
  5. // Syntax: G=append(a1,b1,c1,d1,a2,b2,c2,d2)
  6. //
  7. // This routine appends the dynamics of two state-space systems
  8. // together. It combines the state-space matrices of two systems
  9. // defined by the follwing:
  10. //          .
  11. //         |x1| = |A1 0| |x1| + |B1 0| |u1|
  12. //         |x2|   |0 A2| |x2| + |0 B2| |u2|
  13. //
  14. //         |y1| = |C1 0| |x1| + |D1 0| |u1|
  15. //         |y2|   |0 C2| |x2| + |0 D2| |u2|
  16. //
  17. // where system "1" and system "2" are combined to formed the
  18. // appended system.
  19. //
  20. // The results are returned in a list:
  21. //
  22. //    G.aa = appended A matrix
  23. //    G.ba = appended B matrix
  24. //    G.ca = appended C matrix
  25. //    G.da = appended D matrix
  26. //
  27. // Copyright (C), by Jeffrey B. Layton, 1994
  28. // Version JBL 940922
  29. //-------------------------------------------------------------------
  30.  
  31. rfile abcdchk
  32.  
  33. append = function(a1,b1,c1,d1,a2,b2,c2,d2)
  34. {
  35.    local(nargs,msg,estr,aa,ba,ca,da)
  36.  
  37. // Count number of input arguments
  38.    nargs=0;
  39.    if (exist(a1)) {nargs=nargs+1;}
  40.    if (exist(b1)) {nargs=nargs+1;}
  41.    if (exist(c1)) {nargs=nargs+1;}
  42.    if (exist(d1)) {nargs=nargs+1;}
  43.    if (exist(a2)) {nargs=nargs+1;}
  44.    if (exist(b2)) {nargs=nargs+1;}
  45.    if (exist(c2)) {nargs=nargs+1;}
  46.    if (exist(d2)) {nargs=nargs+1;}
  47.  
  48.    if (nargs != 8) {
  49.        error("APPEND: Error in number of input arguments.");
  50.    }
  51. // Check input systems for compatibility
  52.    msg="";
  53.    msg=abcdchk(a1,b1,c1,d1);
  54.    if (msg != "") {
  55.        estr="APPEND: "+msg;
  56.        error(estr);
  57.    }
  58.  
  59.    msg="";
  60.    msg=abcdchk(a2,b2,c2,d2);
  61.    if (msg != "") {
  62.        estr="APPEND: "+msg;
  63.        error(estr);
  64.    }
  65.  
  66. // Append Dynamics
  67.    aa=[a1,zeros(a1.nr,a2.nc);zeros(a2.nr,a1.nc),a2];
  68.    ba=[b1,zeros(b1.nr,b2.nc);zeros(b2.nr,b1.nc),b2];
  69.    ca=[c1,zeros(c1.nr,c2.nc);zeros(c2.nr,c1.nc),c2];
  70.    da=[d1,zeros(d1.nr,d2.nc);zeros(d2.nr,d1.nc),d2];
  71.  
  72.    return << aa=aa; ba=ba; ca=ca; da=da >>
  73. };
  74.