# HG changeset patch # User jwe # Date 752795765 0 # Node ID 5652a6bca14ca031fc0faef0d32e24bc56b8d63c # Parent cfedacc895e7dd505b710e17491d6c45af0ce364 [project @ 1993-11-08 21:56:05 by jwe] Initial revision diff -r cfedacc895e7 -r 5652a6bca14c scripts/control/c2d.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/control/c2d.m Mon Nov 08 21:56:05 1993 +0000 @@ -0,0 +1,39 @@ +function [Ad, Bd] = c2d (Ac, Bc, T) + +# Usage: [Ad, Bd] = c2d (Ac, Bc, T) +# +# converts the continuous time system described by: +# . +# x = Ac x + Bc u +# +# into a discrete time equivalent model via the matrix exponential +# +# x[n+1] = Ad x[n] + Bd u[n] +# +# assuming a zero-order hold on the input and sample time T. + +# Written by R.B. Tenison (btenison@eng.auburn.edu) +# October 1993 + +# check args + if (nargin != 3) + error ("usage: c2d (Ac, Bc, T)"); + endif + + [ma, na] = size (Ac); + [mb, nb] = size (Bc); + + if (ma != na) + error ("c2d: Ac must be square"); + endif + + if (ma != mb) + error ("c2d: Ac and Bc must have the same number of rows"); + endif + + matexp = expm ([[Ac, Bc] * T; zeros (nb, na+nb)]); + + Ad = matexp (1:na, 1:na); + Bd = matexp (1:na, na+1:na+nb); + +endfunction