changeset 203:5652a6bca14c

[project @ 1993-11-08 21:56:05 by jwe] Initial revision
author jwe
date Mon, 08 Nov 1993 21:56:05 +0000
parents cfedacc895e7
children 7e307bcc208a
files scripts/control/c2d.m
diffstat 1 files changed, 39 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /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