1## Copyright (C) 2009-2016   Lukas F. Reichlin
2##
3## This file is part of LTI Syncope.
4##
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.
9##
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.
14##
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/>.
17
18## -*- texinfo -*-
19## Block diagonal concatenation of two SS models.
20## This file is part of the Model Abstraction Layer.
21## For internal use only.
22
23## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
24## Created: September 2009
25## Version: 0.2
26
27function retsys = __sys_group__ (sys1, sys2)
28
29  if (! isa (sys1, "ss"))
30    sys1 = ss (sys1);
31  endif
32
33  if (! isa (sys2, "ss"))
34    sys2 = ss (sys2);
35  endif
36
37  retsys = ss ();
38  retsys.lti = __lti_group__ (sys1.lti, sys2.lti);
39
40  n1 = rows (sys1.a);
41  n2 = rows (sys2.a);
42
43  [p1, m1] = size (sys1.d);
44  [p2, m2] = size (sys2.d);
45
46  retsys.a = [sys1.a, zeros(n1,n2); zeros(n2,n1), sys2.a];
47  retsys.b = [sys1.b, zeros(n1,m2); zeros(n2,m1), sys2.b];
48  retsys.c = [sys1.c, zeros(p1,n2); zeros(p2,n1), sys2.c];
49  retsys.d = [sys1.d, zeros(p1,m2); zeros(p2,m1), sys2.d];
50
51  e1 = ! isempty (sys1.e);
52  e2 = ! isempty (sys2.e);
53
54  if (e1 || e2)
55    if (e1 && e2)
56      retsys.e = [sys1.e, zeros(n1,n2); zeros(n2,n1), sys2.e];
57    elseif (e1)
58      retsys.e = [sys1.e, zeros(n1,n2); zeros(n2,n1), eye(n2)];
59    else
60      retsys.e = [eye(n1), zeros(n1,n2); zeros(n2,n1), sys2.e];
61    endif
62  endif
63
64  retsys.stname = [sys1.stname; sys2.stname];
65
66endfunction
67