904
|
1 # Copyright (C) 1993, 1994 John W. Eaton |
245
|
2 # |
|
3 # This file is part of Octave. |
|
4 # |
|
5 # Octave is free software; you can redistribute it and/or modify it |
|
6 # under the terms of the GNU General Public License as published by the |
|
7 # Free Software Foundation; either version 2, or (at your option) any |
|
8 # later version. |
|
9 # |
|
10 # Octave is distributed in the hope that it will be useful, but WITHOUT |
|
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 # for more details. |
|
14 # |
|
15 # You should have received a copy of the GNU General Public License |
|
16 # along with Octave; see the file COPYING. If not, write to the Free |
|
17 # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
18 |
203
|
19 function [Ad, Bd] = c2d (Ac, Bc, T) |
|
20 |
|
21 # Usage: [Ad, Bd] = c2d (Ac, Bc, T) |
|
22 # |
|
23 # converts the continuous time system described by: |
|
24 # . |
|
25 # x = Ac x + Bc u |
|
26 # |
|
27 # into a discrete time equivalent model via the matrix exponential |
|
28 # |
|
29 # x[n+1] = Ad x[n] + Bd u[n] |
|
30 # |
|
31 # assuming a zero-order hold on the input and sample time T. |
|
32 |
|
33 # Written by R.B. Tenison (btenison@eng.auburn.edu) |
|
34 # October 1993 |
|
35 |
|
36 # check args |
|
37 if (nargin != 3) |
904
|
38 usage ("c2d (Ac, Bc, T)"); |
203
|
39 endif |
|
40 |
|
41 [ma, na] = size (Ac); |
|
42 [mb, nb] = size (Bc); |
|
43 |
|
44 if (ma != na) |
|
45 error ("c2d: Ac must be square"); |
|
46 endif |
|
47 |
|
48 if (ma != mb) |
|
49 error ("c2d: Ac and Bc must have the same number of rows"); |
|
50 endif |
|
51 |
|
52 matexp = expm ([[Ac, Bc] * T; zeros (nb, na+nb)]); |
|
53 |
|
54 Ad = matexp (1:na, 1:na); |
|
55 Bd = matexp (1:na, na+1:na+nb); |
|
56 |
|
57 endfunction |