1 ## Copyright (C) 2009, 2011 Lukas F. Reichlin
3 ## This file is part of LTI Syncope.
5 ## LTI Syncope is free software: you can redistribute it and/or modify
6 ## it under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation, either version 3 of the License, or
8 ## (at your option) any later version.
10 ## LTI Syncope is distributed in the hope that it will be useful,
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ## GNU General Public License for more details.
15 ## You should have received a copy of the GNU General Public License
16 ## along with LTI Syncope. If not, see <http://www.gnu.org/licenses/>.
19 ## Matrix multiplication of LTI objects. If necessary, object conversion
20 ## is done by sys_group. Used by Octave for "sys1 * sys2".
22 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
23 ## Created: September 2009
26 function sys = mtimes (sys2, sys1)
28 if (nargin != 2) # prevent sys = mtimes (sys1, sys2, sys3, ...)
29 error ("lti: mtimes: this is a binary operator");
32 [p1, m1] = size (sys1);
33 [p2, m2] = size (sys2);
36 error ("lti: mtimes: system dimensions incompatible: (%dx%d) * (%dx%d)",
49 in_idx = m2 + (1 : m1);
51 sys = __sys_group__ (sys2, sys1);
52 sys = __sys_connect__ (sys, M);
53 sys = __sys_prune__ (sys, out_idx, in_idx);
58 ## Alternative code: consistency vs. compatibility
69 out_idx = p1 + (1 : p2);
72 sys = __sys_group__ (sys1, sys2);
74 ## Don't forget to adapt @tf/__sys_connect__.m draft code
78 %!shared sysmat, sysmat_exp
79 %! sys1 = ss ([0, 1; -3, -2], [0; 1], [-5, 1], [2]);
80 %! sys2 = ss ([-10], [1], [-40], [5]);
81 %! sys3 = sys2 * sys1;
82 %! [A, B, C, D] = ssdata (sys3);
83 %! sysmat = [A, B; C, D];
90 %! C_exp = [ -40 -25 5 ];
92 %! sysmat_exp = [A_exp, B_exp; C_exp, D_exp];
93 %!assert (sysmat, sysmat_exp)
96 ## Cascade inter-connection of two systems in state-space form
97 ## Test from SLICOT AB05MD
98 ## TODO: order of united state vector: consistency vs. compatibility?
100 #%! A1 = [ 1.0 0.0 -1.0
104 #%! B1 = [ 1.0 1.0 0.0
107 #%! C1 = [ 3.0 -2.0 1.0
113 #%! A2 = [-3.0 0.0 0.0
117 #%! B2 = [ 0.0 -1.0 0.0
120 #%! C2 = [ 1.0 1.0 0.0
126 #%! sys1 = ss (A1, B1, C1, D1);
127 #%! sys2 = ss (A2, B2, C2, D2);
128 #%! sys = sys2 * sys1;
129 #%! [A, B, C, D] = ssdata (sys);
130 #%! M = [A, B; C, D];
132 #%! Ae = [ 1.0000 0.0000 -1.0000 0.0000 0.0000 0.0000
133 #%! 0.0000 -1.0000 1.0000 0.0000 0.0000 0.0000
134 #%! 1.0000 1.0000 2.0000 0.0000 0.0000 0.0000
135 #%! 0.0000 1.0000 0.0000 -3.0000 0.0000 0.0000
136 #%! -3.0000 2.0000 -1.0000 1.0000 0.0000 1.0000
137 #%! 0.0000 2.0000 0.0000 0.0000 -1.0000 2.0000 ];
139 #%! Be = [ 1.0000 2.0000
146 #%! Ce = [ 3.0000 -1.0000 1.0000 1.0000 1.0000 0.0000
147 #%! 0.0000 1.0000 0.0000 1.0000 1.0000 -1.0000 ];
149 #%! De = [ 1.0000 1.0000
152 #%! Me = [Ae, Be; Ce, De];
154 #%!assert (M, Me, 1e-4);