]> Creatis software - CreaPhase.git/blob - octave_packages/control-2.3.52/ctrbf.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / control-2.3.52 / ctrbf.m
1 ## Copyright (C) 2010   Benjamin Fernandez 
2 ## Copyright (C) 2011   Lukas F. Reichlin
3 ## 
4 ## This file is part of LTI Syncope.
5 ##
6 ## LTI Syncope is free software: you can redistribute it and/or modify
7 ## it under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation, either version 3 of the License, or
9 ## (at your option) any later version.
10 ##
11 ## LTI Syncope is distributed in the hope that it will be useful,
12 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 ## GNU General Public License for more details.
15 ##
16 ## You should have received a copy of the GNU General Public License
17 ## along with LTI Syncope.  If not, see <http://www.gnu.org/licenses/>.
18
19 ## -*- texinfo -*-
20 ## @deftypefn{Function File} {[@var{sysbar}, @var{T}, @var{K}] =} ctrbf (@var{sys})
21 ## @deftypefnx{Function File} {[@var{sysbar}, @var{T}, @var{K}] =} ctrbf (@var{sys}, @var{tol})
22 ## @deftypefnx{Function File} {[@var{Abar}, @var{Bbar}, @var{Cbar}, @var{T}, @var{K}] =} ctrbf (@var{A}, @var{B}, @var{C})
23 ## @deftypefnx{Function File} {[@var{Abar}, @var{Bbar}, @var{Cbar}, @var{T}, @var{K}] =} ctrbf (@var{A}, @var{B}, @var{C}, @var{TOL})
24 ## If Co=ctrb(A,B) has rank r <= n = SIZE(A,1), then there is a 
25 ## similarity transformation Tc such that Tc = [t1 t2] where t1
26 ## is the controllable subspace and t2 is orthogonal to t1
27 ##
28 ## @example
29 ## @group
30 ## Abar = Tc \ A * Tc ,  Bbar = Tc \ B ,  Cbar = C * Tc
31 ## @end group
32 ## @end example
33 ##
34 ## and the transformed system has the form
35 ##
36 ## @example
37 ## @group
38 ##        | Ac    A12|           | Bc |
39 ## Abar = |----------|,   Bbar = | ---|,  Cbar = [Cc | Cnc].
40 ##        | 0     Anc|           |  0 |
41 ## @end group
42 ## @end example
43 ##                                     
44 ## where (Ac,Bc) is controllable, and Cc(sI-Ac)^(-1)Bc = C(sI-A)^(-1)B.
45 ## and the system is stabilizable if Anc has no eigenvalues in
46 ## the right half plane. The last output K is a vector of length n
47 ## containing the number of controllable states.
48 ## @end deftypefn
49
50 ## Author: Benjamin Fernandez <mail@benjaminfernandez.info>
51 ## Created: 2010-04-30
52 ## Version: 0.1
53
54 function [ac, bc, cc, z, ncont] = ctrbf (a, b = [], c, tol = [])
55
56   if (nargin < 1 || nargin > 4)
57     print_usage ();
58   endif
59   
60   islti = isa (a, "lti");
61   
62   if (islti)
63     if (nargin > 2)
64       print_usage ();
65     endif
66     sys = a;
67     tol = b;
68     [a, b, c] = ssdata (sys);
69   else
70     if (nargin < 3)
71       print_usage ();
72     endif
73     sys = ss (a, b, c);
74     [a, b, c] = ssdata (sys);
75   endif
76
77   if (isempty (tol))
78     tol = 0;               # default tolerance
79   elseif (! is_real_scalar (tol))
80     error ("ctrbf: tol must be a real scalar");
81   endif
82
83   [ac, bc, cc, z, ncont] = sltb01ud (a, b, c, tol);
84   
85   if (islti)
86     ac = set (sys, "a", ac, "b", bc, "c", cc, "scaled", false);
87     bc = z;
88     cc = ncont;
89   endif
90   
91 endfunction
92
93 %!shared Ao, Bo, Co, Zo, Ae, Be, Ce, Ze, NCONT
94 %! A =  [ -1.0   0.0   0.0
95 %!        -2.0  -2.0  -2.0
96 %!        -1.0   0.0  -3.0 ];
97 %!
98 %! B =  [  1.0   0.0   0.0
99 %!         0.0   2.0   1.0 ].';
100 %!
101 %! C =  [  0.0   2.0   1.0
102 %!         1.0   0.0   0.0 ];
103 %!
104 %! [Ao, Bo, Co, Zo, NCONT] = ctrbf (A, B, C);
105 %!
106 %! Ae = [ -3.0000   2.2361
107 %!         0.0000  -1.0000 ];
108 %!
109 %! Be = [  0.0000  -2.2361
110 %!         1.0000   0.0000 ];
111 %!
112 %! Ce = [ -2.2361   0.0000
113 %!         0.0000   1.0000 ];
114 %!
115 %! Ze = [  0.0000   1.0000   0.0000
116 %!        -0.8944   0.0000  -0.4472
117 %!        -0.4472   0.0000   0.8944 ];
118 %!
119 %!assert (Ao(1:NCONT, 1:NCONT), Ae, 1e-4);
120 %!assert (Bo(1:NCONT, :), Be, 1e-4);
121 %!assert (Co(:, 1:NCONT), Ce, 1e-4);
122 %!assert (Zo, Ze, 1e-4);