1 ## Copyright (C) 2009, 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 ## Inversion of LTI objects.
21 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
22 ## Created: October 2009
25 function retsys = inv (sys)
27 if (nargin != 1) # prevent sys = inv (sys1, sys2, sys3, ...)
28 error ("lti: inv: this is an unary operator");
34 error ("lti: inv: system must be square");
37 retsys = __sys_inverse__ (sys);
39 ## TODO: handle i/o names
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
63 %! sys = ss (A, B, C, D);
64 %! sysinv = inv (sys);
65 %! [Ai, Bi, Ci, Di] = ssdata (sysinv);
66 %! M = [Ai, Bi; Ci, Di];
68 %! Ae = [ 1.0000 1.7500 0.2500
69 %! 4.0000 -1.0000 -1.0000
70 %! 0.0000 -0.2500 1.2500 ];
72 %! Be = [-0.2500 0.0000
76 %! Ce = [ 0.0000 0.2500 -0.2500
77 %! 0.0000 0.0000 1.0000 ];
79 %! De = [ 0.2500 0.0000
82 %! Me = [Ae, Be; Ce, De]; # Me = [Ae, -Be; -Ce, De];
84 %!assert (M, Me, 1e-4);