]> Creatis software - CreaPhase.git/blob - octave_packages/control-2.3.52/@ss/__sys_connect__.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / control-2.3.52 / @ss / __sys_connect__.m
1 ## Copyright (C) 2009, 2010   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{retsys} =} __sys_connect__ (@var{sys}, @var{M})
20 ## This function is part of the Model Abstraction Layer.  No argument checking.
21 ## For internal use only.
22 ## @example
23 ## @group
24 ## Problem: Solve the system equations of
25 ##   .
26 ## E x(t) = A x(t) + B e(t)
27 ##
28 ##   y(t) = C x(t) + D e(t)
29 ##
30 ##   e(t) = u(t) + M y(t)
31 ##
32 ## in order to build
33 ##   .
34 ## K x(t) = F x(t) + G u(t)
35 ##
36 ##   y(t) = H x(t) + J u(t)
37 ##
38 ## Solution: Laplace Transformation
39 ## E s X(s) = A X(s) + B U(s) + B M Y(s)                     [1]
40 ##
41 ##     Y(s) = C X(s) + D U(s) + D M Y(s)                     [2]
42 ##
43 ## solve [2] for Y(s)
44 ## Y(s) = [I - D M]^(-1) C X(s)  +  [I - D M]^(-1) D U(s)
45 ##
46 ## substitute Z = [I - D M]^(-1)
47 ## Y(s) = Z C X(s) + Z D U(s)                                [3]
48 ##
49 ## insert [3] in [1], solve for X(s)
50 ## X(s) = [s E - (A + B M Z C)]^(-1) (B + B M Z D) U(s)      [4]
51 ##
52 ## inserting [4] in [3] finally yields
53 ## Y(s) = Z C [s E - (A + B M Z C)]^(-1) (B + B M Z D) U(s)  +  Z D U(s)
54 ##        \ /    |   \_____ _____/       \_____ _____/          \ /
55 ##         H     K         F                   G                 J
56 ## @end group
57 ## @end example
58 ## @end deftypefn
59
60 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
61 ## Created: September 2009
62 ## Version: 0.2
63
64 function sys = __sys_connect__ (sys, m)
65
66   a = sys.a;
67   b = sys.b;
68   c = sys.c;
69   d = sys.d;
70
71   z = eye (rows (d)) - d*m;
72
73   if (rcond (z) < eps)  # check for singularity
74     error ("ss: sys_connect: (I - D*M) singular");
75   endif
76
77   z = inv (z);
78
79   sys.a = a + b*m*z*c;  # F
80   sys.b = b + b*m*z*d;  # G
81   sys.c = z*c;          # H
82   sys.d = z*d;          # J
83
84   ## sys.e remains constant: [] for ss models, e for dss models
85
86 endfunction