]> Creatis software - CreaPhase.git/blob - octave_packages/control-2.3.52/@lti/mconnect.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / control-2.3.52 / @lti / mconnect.m
1 ## Copyright (C) 2009, 2010, 2011   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 ## @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.
22 ##
23 ## @strong{Inputs}
24 ## @table @var
25 ## @item sys
26 ## LTI system.
27 ## @item m
28 ## Connection matrix.  Each row belongs to an input and each column represents an output.
29 ## @item inputs
30 ## Vector of indices of those inputs which are retained.  If not specified, all inputs are kept.
31 ## @item outputs
32 ## Vector of indices of those outputs which are retained.  If not specified, all outputs are kept.
33 ## @end table
34 ##
35 ## @strong{Outputs}
36 ## @table @var
37 ## @item sys
38 ## Interconnected system.
39 ## @end table
40 ##
41 ## @strong{Example}
42 ## @example
43 ## @group
44 ## Solve the system equations of
45 ## y(t) = G e(t)
46 ## e(t) = u(t) + M y(t)
47 ## in order to build
48 ## y(t) = H u(t)
49 ## The matrix M for a (p-by-m) system G
50 ## has m rows and p columns (m-by-p).
51 ##
52 ## Example for a 3x2 system:
53 ## u1 = -1*y1 + 5*y2 + 0*y3
54 ## u2 = pi*y1 + 0*y2 - 7*y3
55 ##
56 ##     | -1      5      0 |
57 ## M = | pi      0      7 |
58 ## @end group
59 ## @end example
60 ## @end deftypefn
61
62 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
63 ## Created: October 2009
64 ## Version: 0.2
65
66 function sys = mconnect (sys, M, in_idx, out_idx = ":")
67
68   if (nargin < 2 || nargin > 4)
69     print_usage ();
70   endif
71
72   [p, m] = size (sys);
73   [mrows, mcols] = size (M);
74
75   if (p != mcols || m != mrows)
76     error ("mconnect: second argument must be a (%dx%d) matrix", m, p);
77   endif
78
79   if (! is_real_matrix (M))
80     error ("mconnect: second argument must be a matrix with real coefficients");
81   endif
82
83   sys = __sys_connect__ (sys, M);
84
85   if (nargin > 2)
86     sys = __sys_prune__ (sys, out_idx, in_idx);
87   endif
88
89 endfunction