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
13function [go]=obs_gram(a,c,domaine)
14
15    [lhs,rhs]=argn(0)
16    select typeof(a)
17    case "constant" then
18        if rhs<2 then
19            msg = gettext("%s: Wrong number of input arguments: At least %d expected.\n")
20            error(msprintf(msg, "obs_gram", 2))
21        end;
22        if rhs==2 then domaine="c"; end;
23        if and(domaine<>["d","c"]) then
24            msg = gettext("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n")
25            error(msprintf(msg, "obs_gram",3,"''d'', ''c''"));
26        end
27        [m,n] = size(a)
28        if m<>n then
29            msg = gettext("%s: Argument #%d: Square matrix expected.\n")
30            error(msprintf(msg, "obs_gram", 1))
31        end
32        [mb,nb]=size(c);
33        if nb<>n then
34            msg = gettext("%s: Arguments #%d and #%d: Incompatible sizes.\n")
35            error(msprintf(msg, "obs_gram", 1, 2))
36        end
37    case "state-space" then
38        if rhs>1 then
39            msg = gettext("%s: Wrong number of input arguments: %d expected.\n")
40            error(msprintf(msg, "obs_gram", 1))
41        end
42        [a,c,domaine]=a([2,4,7])
43        if domaine==[] then
44            msg = gettext("%s: Input argument #%d is assumed continuous time.\n")
45            warning(msprintf(msg, "obs_gram", 1));
46            domaine="c";
47        elseif type(domaine)==1 then
48            domaine="d",
49        end
50        [n,n]=size(a)
51    case "rational" then
52        if rhs>1 then
53            msg = gettext("%s: Wrong number of input arguments: %d expected.\n")
54            error(msprintf(msg, "obs_gram", 1)),
55        end
56        a=tf2ss(a)
57        [a,c,domaine] = a([2,4,7])
58        if domaine==[] then
59            msg = gettext("%s: Input argument #%d is assumed continuous time.\n")
60            warning(msprintf(msg, "obs_gram", 1));
61            domaine="c";
62        elseif type(domaine)==1 then
63            domaine="d",
64        end
65        [n,n]=size(a)
66    else
67        if rhs==1 then
68            msg = gettext("%s: Wrong type for input argument #%d: Linear dynamical system  expected.\n")
69            error(msprintf(msg, "obs_gram", 1))
70        else
71            msg = gettext("%s: Wrong type of input argument #%d: Array of floating point numbers expected.\n")
72            error(msprintf(msg, "obs_gram", 1))
73        end
74    end;
75    //
76    s = spec(a)
77    if (domaine=="c"&max(real(s))>=0) | (domaine=="d"&max(abs(s))>=1) then
78        msg = gettext("%s: Wrong value for input argument #%d: Stable system expected.\n")
79        error(msprintf(msg, "obs_gram", 1));
80    end
81    go = lyap(a,-c'*c,domaine)
82endfunction
83