File: hsvd.m

package info (click to toggle)
octave-control 2.3.52-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 4,680 kB
  • sloc: cpp: 5,104; objc: 91; makefile: 52
file content (106 lines) | stat: -rw-r--r-- 3,423 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
## Copyright (C) 2010, 2011   Lukas F. Reichlin
##
## This file is part of LTI Syncope.
##
## LTI Syncope is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## LTI Syncope is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with LTI Syncope.  If not, see <http://www.gnu.org/licenses/>.

## -*- texinfo -*-
## @deftypefn{Function File} {@var{hsv} =} hsvd (@var{sys})
## @deftypefnx{Function File} {@var{hsv} =} hsvd (@var{sys}, @var{"offset"}, @var{offset})
## @deftypefnx{Function File} {@var{hsv} =} hsvd (@var{sys}, @var{"alpha"}, @var{alpha})
## Hankel singular values of the stable part of an LTI model.  If no output arguments are
## given, the Hankel singular values are displayed in a plot.
##
## @strong{Algorithm}@*
## Uses SLICOT AB13AD by courtesy of
## @uref{http://www.slicot.org, NICONET e.V.}
## @end deftypefn

## Author: Lukas Reichlin <lukas.reichlin@gmail.com>
## Created: January 2010
## Version: 0.4

function hsv_r = hsvd (sys, prop = "offset", val = 1e-8)

  if (nargin != 1 && nargin != 3)
    print_usage ();
  endif

  if (! isa (sys, "lti"))
    error ("hsvd: first argument must be an LTI system");
  endif

  if (! is_real_scalar (val))
    error ("hsvd: third argument must be a real scalar");
  endif

  [a, b, c, ~, ~, scaled] = ssdata (sys);

  discrete = ! isct (sys);

  switch (tolower (prop(1)))
    case "o"                 # offset
      if (discrete)
        alpha = 1 - val;
      else
        alpha = - val;
      endif
    case "a"                 # alpha
      alpha = val;
    otherwise
      error ("hsvd: second argument invalid");
  endswitch
  
  [hsv, ns] = slab13ad (a, b, c, discrete, alpha, scaled);
  
  if (nargout)
    hsv_r = hsv;
  else
    bar ((1:ns) + (rows (a) - ns), hsv);
    title (["Hankel Singular Values of Stable Part of ", inputname(1)]);
    xlabel ("State");
    ylabel ("State Energy");
    grid ("on");
  endif

endfunction


%!shared hsv, hsv_exp
%! a = [ -0.04165  0.0000  4.9200  -4.9200  0.0000  0.0000  0.0000
%!       -5.2100  -12.500  0.0000   0.0000  0.0000  0.0000  0.0000
%!        0.0000   3.3300 -3.3300   0.0000  0.0000  0.0000  0.0000
%!        0.5450   0.0000  0.0000   0.0000 -0.5450  0.0000  0.0000
%!        0.0000   0.0000  0.0000   4.9200 -0.04165 0.0000  4.9200
%!        0.0000   0.0000  0.0000   0.0000 -5.2100 -12.500  0.0000
%!        0.0000   0.0000  0.0000   0.0000  0.0000  3.3300 -3.3300];
%!
%! b = [  0.0000   0.0000
%!       12.5000   0.0000
%!        0.0000   0.0000
%!        0.0000   0.0000
%!        0.0000   0.0000
%!        0.0000   12.500
%!        0.0000   0.0000];
%!
%! c = [  1.0000   0.0000  0.0000   0.0000  0.0000  0.0000  0.0000
%!        0.0000   0.0000  0.0000   1.0000  0.0000  0.0000  0.0000
%!        0.0000   0.0000  0.0000   0.0000  1.0000  0.0000  0.0000];
%!
%! sys = ss (a, b, c, [], "scaled", true);
%! hsv = hsvd (sys, "alpha", 0.0);
%!
%! hsv_exp = [2.5139; 2.0846; 1.9178; 0.7666; 0.5473; 0.0253; 0.0246];
%!
%!assert (hsv, hsv_exp, 1e-4);