home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ARM Club 3
/
TheARMClub_PDCD3.iso
/
hensa
/
maths
/
rlab
/
controls
/
CTB
/
step
< prev
next >
Wrap
Text File
|
1995-11-15
|
3KB
|
138 lines
//--------------------------------------------------------------------------------
//
// step
//
// Syntax: G=step(A,B,C,D,IU,T)
//
// This routine plots the step response of continuous-time linear systems.
// It plots the time response of the following linear continuous-time
// system
// .
// x = Ax + Bu
// y = Cx + Du
//
// to a step input applied to the input IU. The routine may be called
// in several fashions:
//
// (1) G=step(A,B,C,D)
// (This produces the step response of the system looping over the
// inputs and looping over the output with an arbitrary time
// vector T=0.0:20.0:0.1).
//
// (2) G=step(A,B,C,D,IU)
// (This produces the step response of the system to the IU input
// and looped over the outputs with an arbitrary time T=0.0:20.0:0.1)
//
// (3) G=step(A,B,C,D,IU,T)
// (This produces the step response of the system to the IU input
// and looped over the outputs for the specified time vector T).
//
// (4) G=step(NUM,DEN)
// (This produces the step response of the transfer function model
// with an arbitrary time T=0.0:20.0:0.1).
//
// (5) G=step(NUM,DEN,T)
// (This produces the step response of the transfer function model to
// for the specified time vector T).
//
// For the cases where the time vector T is specified, the times must
// be regularly spaced.
//
// Note: Two matrices are returned in a list.
//
// G.x = X values in the plot.
// G.y = Y values in the plot.
//
// Note: The matrix G.y has as many columns as there are outputs and
// has length(T) rows. The matrix G.x has as many columns as states
// and has length(T) rows).
//
// Copyright(C), by Jeffrey B. Layton, 1994
// Version JBL 940915
//--------------------------------------------------------------------------------
rfile tfchk
rfile tf2ss
rfile isempty
rfile abcdchk
rfile lsim
step = function(a,b,c,d,iu,t)
{
local(nargs,Dum,num,den,A,B,C,D,msg,estr,IU,T,n,x,y)
// Count number of input arguments
nargs=0;
if (exist(a)) {nargs=nargs+1;}
if (exist(b)) {nargs=nargs+1;}
if (exist(c)) {nargs=nargs+1;}
if (exist(d)) {nargs=nargs+1;}
if (exist(iu)) {nargs=nargs+1;}
if (exist(t)) {nargs=nargs+1;}
// Check system type
if (nargs < 4) {
// T.F. - convert
Dum=tfchk(a,b);
num=Dum.numc;
den=Dum.denc;
Dum=tf2ss(num,den);
A=Dum.a;
B=Dum.b;
C=Dum.c;
D=Dum.d;
IU=1;
if (exist(c)) {
T=c;
if (T.nr == 1) {
T=T.';
}
else
T=[0.0:20.0:0.1];
T=T.';
}
else
// S.S.
A=a;
B=b;
C=c;
D=d;
if (exist(iu)) {
IU=iu;
if (exist(t)) {
T=t;
if (T.nr == 1) {
T=T.';
}
else
T=[0.0:20.0:0.1];
T=T.';
}
else
IU=B.nc;
T=[0.0:20.0:0.1];
T=T.';
}
msg="";
msg=abcdchk(A,B,C,D);
if (msg != "") {
estr="lsim: "+msg;
error(estr);
}
}
// Perform Simulation (use lsim)
n=length(T);
for (i in 1:IU) {
// Set B and D matrices for the ith input
BI=B[;i];
DI=D[;i];
Dum=lsim(A,BI,C,DI,ones(n,1),T,zeros(BI.nr,BI.nc));
x=Dum.x;
y=Dum.y;
}
return << x=x; y=y >>
};