home *** CD-ROM | disk | FTP | other *** search
- //-----------------------------------------------------------------------
- //
- // cloop
- //
- // Syntax: G = cloop(a,b,c,d,e,f)
- //
- // This routine closes the loop of either a state-space system or
- // a transfer function system for either a continuous or discrete system,
- // using unity feedback. Three cases of input arguments are possible:
- //
- // State Space Case
- // ------------------------
- //
- // Calling the routine with G=cloop(a,b,c,d,sign) will produce a
- // state-space model of the closed loop system obtained by feeding
- // all of the outputs to all of the inputs. If sign = 1 then positive
- // feedback is used. If sign = -1 then negative feedback is used.
- // In either case, the resulting system will have all of the same inputs
- // and outputs of the original model.
- // Note: A list is returned containing the closed loop model.
- // G.ac = Closed Loop A matrix
- // G.bc = Closed Loop B matrix
- // G.cc = Closed Loop C matrix
- // G.dc = Closed Loop D matrix
- //
- // State Space Case with Specified Inputs and Outputs
- // ----------------------------------------------------------
- //
- // Calling the routine with G=cloop(a,b,c,d,outputs,inputs) will
- // produce a state-space model of the closed loop system which
- // is obtained by feeding back the specified outputs to the
- // specified inputs. The vector "outputs" contains indices of the
- // desired outputs and the vector "inputs" contains indices of the
- // desired inputs. Positive feedback is assumed in this case.
- // If negative feedback is desired, then the vector "inputs" needs
- // to have negative values.
- // Note: A list is returned containing the closed loop model.
- // G.ac = Closed Loop A matrix
- // G.bc = Closed Loop B matrix
- // G.cc = Closed Loop C matrix
- // G.dc = Closed Loop D matrix
- //
- // Transfer Function Case
- // ------------------------------
- //
- // Calling the routine with G=cloop(num,den,sign) produces the SISO
- // model of the closed loop system obtained by unity feedback with
- // the sign "sign" (positive or negative feedback).
- // Note: A list is returned containing the closed loop model.
- // G.ac = Closed loop numerator
- // G.bc = Closed Loop denominator
- // G.cc = empty
- // G.dc = empty
- //
- // Copyright (C), by Jeffrey B. Layton, 1994-95
- // Version JBL 950106
- //-----------------------------------------------------------------------
-
- rfile tfchk
- rfile abcdchk
-
- cloop = function(a,b,c,d,e,f)
- {
- local(A,sgn2,term1,term2,term3,narg,msg,inputs,outputs,nout,dtil,...
- dbar,bbar,ctil,dtilbar,ac,bc,cc,dc,estr)
-
- // Count number of input arguments
- narg=0;
- if (exist(a)) {narg=narg+1;}
- if (exist(b)) {narg=narg+1;}
- if (exist(c)) {narg=narg+1;}
- if (exist(d)) {narg=narg+1;}
- if (exist(e)) {narg=narg+1;}
- if (exist(f)) {narg=narg+1;}
-
- // Determine which syntax is being used.
- // -------------------------------------
-
- if (narg == 2) {
- // transfer function without sign on feedback
- A=tfchk(a,b);
-
- ac=A.numc;
- bc=A.denc-A.numc;
- cc=[];
- dc=[];
- }
- if (narg == 3) {
- // transfer function with sign on feedback
- A=tfchk(a,b);
-
- ac=A.numc;
- bc=A.denc-sign(c)*A.numc;
- cc=[];
- dc=[];
- }
-
- if (narg >= 4) {
- // State Space model
- msg="";
- msg=abcdchk(a,b);
- if (msg != "") {
- estr="CLOOP: "+msg;
- error(estr);
- }
-
- // define "input" and "outputs"
- if (narg == 4) {
- outputs=1:c.nr;
- inputs=1:b.nc;
- sgn2=-1;
- }
- if (narg == 5) {
- outputs=1:c.nr;
- inputs=[1:b.nc];
- sgn2=sign(e);
- }
- if (narg == 6) {
- outputs=e;
- inputs=abs(f);
- if (sign(f[1]) > 0 ) {
- sgn2=1;
- else
- sgn2=-1;
- }
- }
-
- // Form Closed Loop State-space System
- nout=length(outputs);
- if (length(inputs) != length(outputs)) {
- error("CLOOP: The number of feedback inputs and outputs are not equal");
- }
-
- dtil=d[outputs;];
- dbar=d[;inputs];
- bbar=b[;inputs];
- ctil=c[outputs;];
-
- dtilbar=dtil[;inputs];
- if (sgn2 > 0) {
- term1=eye(nout,nout)-dtilbar;
- else
- term1=eye(nout,nout)+dtilbar;
- }
-
- term2=solve(term1',dbar')';
- term3=solve(term1',bbar')';
- dc=d+sgn2*term2*dtil;
- bc=b+sgn2*term3*dtil;
- cc=c+sgn2*term2*ctil;
- ac=a+sgn2*term3*ctil;
- }
-
- return << ac=ac; bc=bc; cc=cc; dc=dc >>
- };
-