]> Creatis software - CreaPhase.git/blob - octave_packages/control-2.3.52/@lti/inv.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / control-2.3.52 / @lti / inv.m
1 ## Copyright (C) 2009, 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 ## Inversion of LTI objects.
20
21 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
22 ## Created: October 2009
23 ## Version: 0.2
24
25 function retsys = inv (sys)
26
27   if (nargin != 1)  # prevent sys = inv (sys1, sys2, sys3, ...)
28     error ("lti: inv: this is an unary operator");
29   endif
30
31   [p, m] = size (sys);
32
33   if (p != m)
34     error ("lti: inv: system must be square");
35   endif
36
37   retsys = __sys_inverse__ (sys);
38
39   ## TODO: handle i/o names
40
41 endfunction
42
43
44 ## inverse of state-space models
45 ## test from SLICOT AB07ND
46 ## result differs intentionally from a commercial
47 ## implementation of an octave-like language
48 %!shared M, Me
49 %! A = [ 1.0   2.0   0.0
50 %!       4.0  -1.0   0.0
51 %!       0.0   0.0   1.0 ];
52 %!
53 %! B = [ 1.0   0.0
54 %!       0.0   1.0
55 %!       1.0   0.0 ];
56 %!
57 %! C = [ 0.0   1.0  -1.0
58 %!       0.0   0.0   1.0 ];
59 %!
60 %! D = [ 4.0   0.0
61 %!       0.0   1.0 ];
62 %!
63 %! sys = ss (A, B, C, D);
64 %! sysinv = inv (sys);
65 %! [Ai, Bi, Ci, Di] = ssdata (sysinv);
66 %! M = [Ai, Bi; Ci, Di];
67 %!
68 %! Ae = [ 1.0000   1.7500   0.2500
69 %!        4.0000  -1.0000  -1.0000
70 %!        0.0000  -0.2500   1.2500 ];
71 %!
72 %! Be = [-0.2500   0.0000
73 %!        0.0000  -1.0000
74 %!       -0.2500   0.0000 ];
75 %!
76 %! Ce = [ 0.0000   0.2500  -0.2500
77 %!        0.0000   0.0000   1.0000 ];
78 %!
79 %! De = [ 0.2500   0.0000
80 %!        0.0000   1.0000 ];
81 %!
82 %! Me = [Ae, Be; Ce, De];  # Me = [Ae, -Be; -Ce, De];
83 %!
84 %!assert (M, Me, 1e-4);