summaryrefslogtreecommitdiff
path: root/modules/overloading/macros/%lss_m_lss.sci
blob: ad2994e43f70a7d5fd98a92ab7c5e7377e44547f (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
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
// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) INRIA
//
// 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 [SS]=%lss_m_lss(S1,S2)
    //S=%lss_m_lss(S1,S2)  computes S1*S2 in state-space form.
    //  --> S2 --> S1 -->
    //!

    [S1,S2]=sysconv(S1,S2)
    [A1,B1,C1,D1,x1,dom1]=S1(2:7),
    [A2,B2,C2,D2,x2]=S2(2:6),
    //
    if max(degree(D1))==0 & max(degree(D2))==0 then
        D1=coeff(D1);D2=coeff(D2);
        B1C2=B1*C2
        SS=tlist(["lss","A","B","C","D","X0","dt"],[A1,B1C2;0*B1C2' ,A2],[B1*D2;B2],...
        [C1,D1*C2],D1*D2,[x1;x2],dom1),
        return
    end
    //improper systems

    J=[A1,B1*C2;
    0*ones(B1*C2)',A2];
    Ls=[C1 D1*C2]'
    Ms=[B1*D2;B2]

    if Ms==[]|Ls==[] then
        SS=tlist(["lss","A","B","C","D","X0","dt"],[],[],[],D1*D2,[x1;x2],dom1)
        return;
    end
    //
    if type(D1*D2)~=1
        s=poly(0,varn(D1*D2));
    end
    deg=max(degree(Ms));
    B=coeff(Ms,deg);
    Ps=0*B
    for i=1:deg
        Ps=s*Ps+B
        B=J*B+coeff(Ms,deg-i)
    end
    //
    deg=max(degree(Ls));  J=J'
    C=coeff(Ls,deg);
    pps=0*C
    for i=1:deg
        pps=s*pps+C
        C=J*C+coeff(Ls,deg-i)
    end
    //
    C=C';
    D=pps'*B+Ls'*Ps+D1*D2;
    Dg=max(degree(D));
    if Dg==0 then D=coeff(D);end

    SS=tlist(["lss","A","B","C","D","X0","dt"],J',B,C,D,[x1;x2],dom1);
endfunction