1 ## Copyright (C) 2009, 2010, 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 ## @deftypefn {Function File} {@var{sys} =} mconnect (@var{sys}, @var{m})
20 ## @deftypefnx {Function File} {@var{sys} =} mconnect (@var{sys}, @var{m}, @var{inputs}, @var{outputs})
21 ## Arbitrary interconnections between the inputs and outputs of an LTI model.
28 ## Connection matrix. Each row belongs to an input and each column represents an output.
30 ## Vector of indices of those inputs which are retained. If not specified, all inputs are kept.
32 ## Vector of indices of those outputs which are retained. If not specified, all outputs are kept.
38 ## Interconnected system.
44 ## Solve the system equations of
46 ## e(t) = u(t) + M y(t)
49 ## The matrix M for a (p-by-m) system G
50 ## has m rows and p columns (m-by-p).
52 ## Example for a 3x2 system:
53 ## u1 = -1*y1 + 5*y2 + 0*y3
54 ## u2 = pi*y1 + 0*y2 - 7*y3
62 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
63 ## Created: October 2009
66 function sys = mconnect (sys, M, in_idx, out_idx = ":")
68 if (nargin < 2 || nargin > 4)
73 [mrows, mcols] = size (M);
75 if (p != mcols || m != mrows)
76 error ("mconnect: second argument must be a (%dx%d) matrix", m, p);
79 if (! is_real_matrix (M))
80 error ("mconnect: second argument must be a matrix with real coefficients");
83 sys = __sys_connect__ (sys, M);
86 sys = __sys_prune__ (sys, out_idx, in_idx);