home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 4
/
DATAFILE_PDCD4.iso
/
languages
/
rlab1_23a
/
CTB
/
c2d
< prev
next >
Wrap
Text File
|
1995-11-14
|
2KB
|
70 lines
//-----------------------------------------------------------------------------
//
// c2d
//
// Syntax: G=c2d(A,B,T)
//
// This routine converts a continuous time system given by:
// .
// x = Ax + Bu
//
// to the discrete time state space system:
//
// x[n+1] = phi * x[n] + gamma * u[n]
//
// It assumes that there is a zero-hold on the inputs and that
// it has a sampling time of T.
//
// The results are returned in a list:
//
// G.phi = phi
// G.gamma = gamma
//
// Ref: Frankin, G. F., Powell, J. D., Workman, M. L., "Digital Control of
// Dynamic Systems," Addison-Wesley, Reading Mass., 1990.
//
// Note: This zero order hold conversion was just taken from the ref.
// as a special case of the first order hold with triangle
// approximation.
//
// Copyright (C), by Jeffrey B. Layton, 1994
// Version JBL 940918
//-----------------------------------------------------------------------------
rfile abcdchk
rfile expm
c2d = function(A,B,T)
{
local(nargs,msg,estr,FT,E,phi,gamma)
// Count number of input arguments
nargs=0;
if (exist(A)) {nargs=nargs+1;}
if (exist(B)) {nargs=nargs+1;}
if (exist(T)) {nargs=nargs+1;}
if (nargs < 3) {
error("C2D: Wrong number of Input arguments.");
}
// Check A,B to ensure that it is correct
msg="";
msg=abcdchk(A,B);
if (msg != "") {
estr="C2D: "+msg;
error(estr);
}
// Form FT matrix and take matrix exponential
FT=[ A, B;
zeros(B.nc,A.nr), zeros(B.nc,B.nc)];
E=expm(FT*T);
// Find Phi and Gamma partitions of E
phi=E[1:A.nr;1:A.nr];
gamma=E[1:A.nr;(A.nr+1):(A.nr+B.nc)];
return << phi=phi; gamma=gamma >>
};