summaryrefslogtreecommitdiff
path: root/modules/cacsd/macros/findAC.sci
blob: bdda5148b58f538ba9007f5f7a36bf118d40ea97 (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
function [A,C,rcnd]=findAC(s,n,l,R,meth,tol,printw)
    A=[];C=[];rcnd=[];
    [nargout,nargin] = argn(0)
    //FINDAC  Finds the system matrices A and C of a discrete-time system, given the
    //        system order and the relevant part of the R factor of the concatenated
    //        block-Hankel matrices, using subspace identification techniques (MOESP
    //        or N4SID).
    //
    //        [A,C] = FINDAC(S,N,L,R,METH,TOL,PRINTW)  computes the system matrices
    //        A and C. The model structure is:
    //
    //             x(k+1) = Ax(k) + Bu(k) + Ke(k),   k >= 1,
    //             y(k)   = Cx(k) + Du(k) + e(k),
    //
    //        where x(k) and y(k) are vectors of length N and L, respectively.
    //
    //        [A,C,RCND] = FINDAC(S,N,L,R,METH,TOL,PRINTW)  also returns the vector
    //        RCND of length 4 containing the condition numbers of the matrices
    //        involved in rank decisions.
    //
    //        S is the number of block rows in the block-Hankel matrices.
    //
    //        METH is an option for the method to use:
    //        METH = 1 :  MOESP method with past inputs and outputs;
    //             = 2 :  N4SID method.
    //        Default:    METH = 1.
    //        Matrix R, computed by FINDR, should be determined with suitable arguments
    //        METH and JOBD.
    //
    //        TOL is the tolerance used for estimating the rank of matrices.
    //        If  TOL > 0,  then the given value of  TOL  is used as a lower bound
    //        for the reciprocal condition number.
    //        Default:    prod(size(matrix))*epsilon_machine where epsilon_machine
    //                    is the relative machine precision.
    //
    //        PRINTW is a select for printing the warning messages.
    //        PRINTW = 1: print warning messages;
    //               = 0: do not print warning messages.
    //        Default:    PRINTW = 0.
    //
    //        See also FINDABCD, FINDBD, FINDBDK, FINDR, ORDER, SIDENT
    //

    //        V. Sima 18-01-2000.
    //
    //        Revisions:
    //

    nin = nargin;
    nout = nargout;
    //
    if nin<7 then
        printw = 0;
    end
    if nin<6 then tol = 0;end
    if tol==[] then tol = 0;end
    if nin<5 then meth = 1;end
    if meth==[] then meth = 1;end
    if nin<4 then
        error(msprintf(gettext("%s: Wrong number of input arguments: %d to %d expected.\n"),"findAC",4,7));
    end
    //
    // Compute system matrices A and C.
    job = 2;
    nsmpl = 0;
    if nout==1 then
        A = sident(meth,job,s,n,l,R,tol,nsmpl,[],[],printw);
    elseif nout==2 then
        [A,C] = sident(meth,job,s,n,l,R,tol,nsmpl,[],[],printw);
    elseif nout==3 then
        [A,C,rcnd] = sident(meth,job,s,n,l,R,tol,nsmpl,[],[],printw);
    else
        error(msprintf(gettext("%s: Wrong number of output arguments: %d to %d expected.\n"),"findAC",1,3));
    end
    //
    // end findAC
endfunction