]> Creatis software - CreaPhase.git/blob - octave_packages/control-2.3.52/hsvd.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / control-2.3.52 / hsvd.m
1 ## Copyright (C) 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{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.
24 ##
25 ## @strong{Algorithm}@*
26 ## Uses SLICOT AB13AD by courtesy of
27 ## @uref{http://www.slicot.org, NICONET e.V.}
28 ## @end deftypefn
29
30 ## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
31 ## Created: January 2010
32 ## Version: 0.4
33
34 function hsv_r = hsvd (sys, prop = "offset", val = 1e-8)
35
36   if (nargin != 1 && nargin != 3)
37     print_usage ();
38   endif
39
40   if (! isa (sys, "lti"))
41     error ("hsvd: first argument must be an LTI system");
42   endif
43
44   if (! is_real_scalar (val))
45     error ("hsvd: third argument must be a real scalar");
46   endif
47
48   [a, b, c, ~, ~, scaled] = ssdata (sys);
49
50   discrete = ! isct (sys);
51
52   switch (tolower (prop(1)))
53     case "o"                 # offset
54       if (discrete)
55         alpha = 1 - val;
56       else
57         alpha = - val;
58       endif
59     case "a"                 # alpha
60       alpha = val;
61     otherwise
62       error ("hsvd: second argument invalid");
63   endswitch
64   
65   [hsv, ns] = slab13ad (a, b, c, discrete, alpha, scaled);
66   
67   if (nargout)
68     hsv_r = hsv;
69   else
70     bar ((1:ns) + (rows (a) - ns), hsv);
71     title (["Hankel Singular Values of Stable Part of ", inputname(1)]);
72     xlabel ("State");
73     ylabel ("State Energy");
74     grid ("on");
75   endif
76
77 endfunction
78
79
80 %!shared hsv, hsv_exp
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];
88 %!
89 %! b = [  0.0000   0.0000
90 %!       12.5000   0.0000
91 %!        0.0000   0.0000
92 %!        0.0000   0.0000
93 %!        0.0000   0.0000
94 %!        0.0000   12.500
95 %!        0.0000   0.0000];
96 %!
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];
100 %!
101 %! sys = ss (a, b, c, [], "scaled", true);
102 %! hsv = hsvd (sys, "alpha", 0.0);
103 %!
104 %! hsv_exp = [2.5139; 2.0846; 1.9178; 0.7666; 0.5473; 0.0253; 0.0246];
105 %!
106 %!assert (hsv, hsv_exp, 1e-4);