879f561ddf1068471faaa3069fec09cc5b12b2e6
[scilab.git] / scilab / modules / cacsd / macros / ctr_gram.sci
1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) INRIA -
3 //
4 // Copyright (C) 2012 - 2016 - Scilab Enterprises
5 //
6 // This file is hereby licensed under the terms of the GNU GPL v2.0,
7 // pursuant to article 5.3.4 of the CeCILL v.2.1.
8 // This file was originally licensed under the terms of the CeCILL v2.1,
9 // and continues to be available under such terms.
10 // For more information, see the COPYING file which you should have received
11 // along with this program.
12
13
14 function [gc]=ctr_gram(a,b,domaine)
15     //!
16
17     [lhs,rhs]=argn(0)
18     select typeof(a)
19     case "constant" then
20         if rhs<2 then error(39); end;
21         if rhs==2 then
22             domaine="c";
23         else
24             if and(domaine<>["d","c"]) then
25                 error(msprintf(gettext("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"), "ctr_gram",3,"''d'', ''c''"));
26             end
27         end;
28         [m,n]=size(a)
29         if m<>n then error(20,1),end
30         [mb,nb]=size(b);if mb<>n then error(60),end
31     case "state-space" then
32         if rhs>1 then
33             error(msprintf(gettext("%s: Wrong number of input arguments: %d expected"),"ctr_gram",1)),
34         end
35         [a,b,domaine]=a([2,3,7])
36         if domaine==[] then
37             warning(msprintf(gettext("%s: Input argument %d is assumed continuous time.\n"),"ctr_gram",1));
38             domaine="c";
39         elseif type(domaine)==1 then
40             domaine="d",
41         end
42         [n,n]=size(a)
43     case "rational" then
44         if rhs>1 then
45             error(msprintf(gettext("%s: Wrong number of input arguments: %d expected"),"ctr_gram",1)),
46         end
47         a=tf2ss(a)
48         [a,b,domaine]=a([2,3,7])
49         if domaine==[] then
50             warning(msprintf(gettext("%s: Input argument %d is assumed continuous time.\n"),"ctr_gram",1));
51             domaine="c";
52         elseif type(domaine)==1 then
53             domaine="d",
54         end
55         [n,n]=size(a)
56     else
57         if rhs==1 then
58             error(msprintf(gettext("%s: Wrong type for input argument #%d: Linear dynamical system expected.\n"),"ctr_gram",1))
59         else
60             error(msprintf(gettext("%s: Wrong type of input argument #%d: Array of floating point numbers expected.\n"),"ctr_gram",1))
61         end
62     end
63     s=spec(a)
64     if (domaine=="c"&max(real(s))>=0)|(domaine=="d"&max(abs(s))>=1) then
65         error(msprintf(gettext("%s: Wrong value for input argument #%d: Stable system expected.\n"),"ctr_gram",1));
66     end
67     gc=lyap(a',-b*b',domaine)
68 endfunction