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

  1. //----------------------------------------------------------------------------------
  2. //
  3. // ssselect
  4. //
  5. // Syntax: A=ssselect(a,b,c,d,inputs,outputs,states)
  6. //
  7. // This routine extracts a subsystem from a larger system. Calling this
  8. // routine as A=ssselect(a,b,c,d,inputs,outputs) will return the state
  9. // space subsystem with the specified inputs and outputs (vectors that
  10. // are input to the routine). Notice that the vectors input and output
  11. // contain indices into the system inputs and outputs.
  12. //
  13. // Calling the routine as A=ssselect(a,b,c,d,inputs,outputs,states) will return
  14. // the state space subsystem with the specified inputs, outputs, and states.
  15. //    and states.
  16. //
  17. // Note: The matrices ae, be, ce, and de are returned in a list.
  18. //
  19. // A.ae = ae matrix.
  20. // A.be = be matrix.
  21. // A.ce = ce matrix.
  22. // A.de = de matrix.
  23. //
  24. // Copyright (C), by Jeffrey B. Layton, 1994
  25. // Version JBL 940405
  26. //----------------------------------------------------------------------------------
  27.  
  28. rfile abcdchk
  29. rfile isempty
  30.  
  31. ssselect = function(a,b,c,d,inputs,outputs,states)
  32. {
  33.    local(narg,msg,estr,innew,outnew,statenew,ae,be,ce,de)
  34.  
  35. // Count number of input arguments
  36.    narg=0;
  37.    if (exist(a)) {narg=narg+1;}
  38.    if (exist(b)) {narg=narg+1;}
  39.    if (exist(c)) {narg=narg+1;}
  40.    if (exist(d)) {narg=narg+1;}
  41.    if (exist(inputs)) {narg=narg+1;}
  42.    if (exist(outputs)) {narg=narg+1;}
  43.    if (exist(states)) {narg=narg+1;}
  44.  
  45. // Check a,b,c,d system to be sure it is valid
  46.    msg="";
  47.    msg=abcdchk(a,b,c,d);
  48.    if (msg != "") {
  49.        estr="SSSELECT: "+msg;
  50.        error(estr);
  51.    }
  52.  
  53. // Create vectors describing new inputs, outputs, and states
  54.    if (narg == 6) {
  55.        innew=inputs;
  56.        outnew=outputs;
  57.        statenew=1:a.nr;
  58.    }
  59.    if (narg == 7) {
  60.        innew=inputs;
  61.        outnew=outputs;
  62.        statenew=states;
  63.    }
  64.  
  65. // Select system 
  66.    ae=a[statenew;statenew];
  67.    be=b[statenew;outnew];
  68.    ce=c[outnew;statenew];
  69.    de=d[outnew;innew];
  70.  
  71.    return << ae=ae; be=be; ce=ce; de=de >>
  72. };
  73.