summaryrefslogtreecommitdiff
path: root/modules/cacsd/macros/gcare.sci
blob: 50502b5b5808f28487694548729234e2a561e7c3 (plain)
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
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) INRIA - F. Delebecque
//
// This file must be used under the terms of the CeCILL.
// This source file is licensed as described in the file COPYING, which
// you should have received as part of this distribution.  The terms
// are also available at
// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt

function [X,F]=gcare(Sl)
    //[X,F]=gcare(Sl)
    //Generalized Control Algebraic Riccati Equation
    //X = solution , F = gain
    //!
    if typeof(Sl)<>"state-space" then
        error(msprintf(gettext("%s: Wrong type for input argument #%d: Linear state space expected.\n"),"gcare",1))
    end
    if Sl.dt<>"c" then
        error(msprintf(gettext("%s: Wrong type for argument #%d: In continuous time expected.\n"),"gcare",1))
    end

    [A,B,C,D]=abcd(Sl);
    S=eye()+D'*D;R=eye()+D*D';
    Si=inv(S);
    Ar=A-B*Si*D'*C;
    H=[Ar,-B*Si*B';
    -C'*inv(R)*C,-Ar'];
    X=ric_desc(H);
    F=-Si*(D'*C+B'*X)
endfunction