1 ## Copyright (C) 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{hsv} =} hsvd (@var{sys})
20 ## @deftypefnx{Function File} {@var{hsv} =} hsvd (@var{sys}, @var{"offset"}, @var{offset})
21 ## @deftypefnx{Function File} {@var{hsv} =} hsvd (@var{sys}, @var{"alpha"}, @var{alpha})
22 ## Hankel singular values of the stable part of an LTI model. If no output arguments are
23 ## given, the Hankel singular values are displayed in a plot.
25 ## @strong{Algorithm}@*
26 ## Uses SLICOT AB13AD by courtesy of
27 ## @uref{http://www.slicot.org, NICONET e.V.}
30 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
31 ## Created: January 2010
34 function hsv_r = hsvd (sys, prop = "offset", val = 1e-8)
36 if (nargin != 1 && nargin != 3)
40 if (! isa (sys, "lti"))
41 error ("hsvd: first argument must be an LTI system");
44 if (! is_real_scalar (val))
45 error ("hsvd: third argument must be a real scalar");
48 [a, b, c, ~, ~, scaled] = ssdata (sys);
50 discrete = ! isct (sys);
52 switch (tolower (prop(1)))
62 error ("hsvd: second argument invalid");
65 [hsv, ns] = slab13ad (a, b, c, discrete, alpha, scaled);
70 bar ((1:ns) + (rows (a) - ns), hsv);
71 title (["Hankel Singular Values of Stable Part of ", inputname(1)]);
73 ylabel ("State Energy");
81 %! a = [ -0.04165 0.0000 4.9200 -4.9200 0.0000 0.0000 0.0000
82 %! -5.2100 -12.500 0.0000 0.0000 0.0000 0.0000 0.0000
83 %! 0.0000 3.3300 -3.3300 0.0000 0.0000 0.0000 0.0000
84 %! 0.5450 0.0000 0.0000 0.0000 -0.5450 0.0000 0.0000
85 %! 0.0000 0.0000 0.0000 4.9200 -0.04165 0.0000 4.9200
86 %! 0.0000 0.0000 0.0000 0.0000 -5.2100 -12.500 0.0000
87 %! 0.0000 0.0000 0.0000 0.0000 0.0000 3.3300 -3.3300];
89 %! b = [ 0.0000 0.0000
97 %! c = [ 1.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
98 %! 0.0000 0.0000 0.0000 1.0000 0.0000 0.0000 0.0000
99 %! 0.0000 0.0000 0.0000 0.0000 1.0000 0.0000 0.0000];
101 %! sys = ss (a, b, c, [], "scaled", true);
102 %! hsv = hsvd (sys, "alpha", 0.0);
104 %! hsv_exp = [2.5139; 2.0846; 1.9178; 0.7666; 0.5473; 0.0253; 0.0246];
106 %!assert (hsv, hsv_exp, 1e-4);