<?xml version="1.0" encoding="UTF-8"?>
<!--
 * Scilab ( https://www.scilab.org/ ) - This file is part of Scilab
 * Copyright (C) INRIA -
 * Copyright (C) 2012 - 2016 - Scilab Enterprises
 *
 * This file is hereby licensed under the terms of the GNU GPL v2.0,
 * pursuant to article 5.3.4 of the CeCILL v.2.1.
 * This file was originally licensed under the terms of the CeCILL v2.1,
 * and continues to be available under such terms.
 * For more information, see the COPYING file which you should have received
 * along with this program.
 *
 -->
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
          xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML"
          xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org"
          xml:lang="en" xml:id="findR">
    <refnamediv>
        <refname>findR</refname>
        <refpurpose>Preprocessor for estimating the matrices of a linear time-invariant dynamical system</refpurpose>
    </refnamediv>
    <refsynopsisdiv>
        <title>Syntax</title>
        <synopsis>
            [R, N] = findR(S, Y)
            [R, N] = findR(S, Y, U, METH, ALG, JOBD, TOL, PRINTW)
            [R, N, SVAL, RCND] = findR(S, Y, U, METH, ALG, JOBD, TOL, PRINTW)
        </synopsis>
    </refsynopsisdiv>
    <refsection>
        <title>Arguments</title>
        <variablelist>
            <varlistentry>
                <term>S</term>
                <listitem>
                    <para>the number of block rows in the block-Hankel matrices.</para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>Y</term>
                <listitem>
                    <para/>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>U</term>
                <listitem>
                    <para/>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>METH</term>
                <listitem>
                    <para>an option for the method to use:</para>
                    <variablelist>
                        <varlistentry>
                            <term>1</term>
                            <listitem>
                                <para> MOESP method with past inputs and outputs;</para>
                            </listitem>
                        </varlistentry>
                        <varlistentry>
                            <term>2</term>
                            <listitem>
                                <para> N4SI15     0     1     1  1000D method.</para>
                            </listitem>
                        </varlistentry>
                    </variablelist>
                    <para>
                        Default:    METH = 1.
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>ALG</term>
                <listitem>
                    <para>an option for the algorithm to compute the triangular factor of the concatenated block-Hankel matrices built from the input-output data:</para>
                    <variablelist>
                        <varlistentry>
                            <term>1</term>
                            <listitem>
                                <para>  Cholesky algorithm on the correlation matrix;</para>
                            </listitem>
                        </varlistentry>
                        <varlistentry>
                            <term>2</term>
                            <listitem>
                                <para>  fast QR algorithm;</para>
                            </listitem>
                        </varlistentry>
                        <varlistentry>
                            <term>3</term>
                            <listitem>
                                <para>  standard QR algorithm.</para>
                            </listitem>
                        </varlistentry>
                    </variablelist>
                    <para>
                        Default:    ALG = 1.
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>JOBD</term>
                <listitem>
                    <para>an option to specify if the matrices B and D should later be computed using the MOESP approach:</para>
                    <variablelist>
                        <varlistentry>
                            <term>=  </term>
                            <listitem>
                                <para>1 :  the matrices B and D should later be computed using the MOESP approach;</para>
                            </listitem>
                        </varlistentry>
                        <varlistentry>
                            <term>=  </term>
                            <listitem>
                                <para>2 :  the matrices B and D should not be computed using the MOESP approach.</para>
                            </listitem>
                        </varlistentry>
                    </variablelist>
                    <para>
                        Default: JOBD = 2. This parameter is not relevant for METH = 2.
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>TOL</term>
                <listitem>
                    <para>a vector of length 2 containing tolerances:</para>
                    <variablelist>
                        <varlistentry>
                            <term>TOL</term>
                            <listitem>
                                <para>(1) is the tolerance for estimating the rank of matrices. If  TOL(1) &gt; 0,  the given value of  TOL(1)  is used as a lower bound for the reciprocal condition number.</para>
                                <para>
                                    Default:    TOL(1) = prod(size(matrix))*epsilon_machine where epsilon_machine is the relative machine precision.
                                </para>
                            </listitem>
                        </varlistentry>
                        <varlistentry>
                            <term>TOL</term>
                            <listitem>
                                <para>(2) is the tolerance for estimating the system order. If  TOL(2) &gt;= 0,  the estimate is indicated by the index of the last singular value greater than or equal to  TOL(2).  (Singular values less than  TOL(2) are considered as zero.)</para>
                                <para>
                                    When  TOL(2) = 0,  then  S*epsilon_machine*sval(1)  is used instead TOL(2),  where  sval(1)  is the maximal singular value. When  TOL(2) &lt; 0,  the estimate is indicated by the index of the singular value that has the largest logarithmic gap to its successor. Default:    TOL(2) = -1.
                                </para>
                            </listitem>
                        </varlistentry>
                    </variablelist>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>PRINTW</term>
                <listitem>
                    <para>a switch for printing the warning messages.</para>
                    <variablelist>
                        <varlistentry>
                            <term>=  </term>
                            <listitem>
                                <para>1: print warning messages;</para>
                            </listitem>
                        </varlistentry>
                        <varlistentry>
                            <term>=  </term>
                            <listitem>
                                <para>0: do not print warning messages.</para>
                            </listitem>
                        </varlistentry>
                    </variablelist>
                    <para>
                        Default:    PRINTW = 0.
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>R</term>
                <listitem>
                    <para/>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>N</term>
                <listitem>
                    <para>the order of the discrete-time realization</para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>SVAL</term>
                <listitem>
                    <para>singular values SVAL, used for estimating the order.</para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>RCND</term>
                <listitem>
                    <para>vector of length 2 containing the reciprocal condition numbers of the matrices involved in rank decisions or least squares solutions.</para>
                </listitem>
            </varlistentry>
        </variablelist>
    </refsection>
    <refsection>
        <title>Description</title>
        <para>
            findR   Preprocesses the input-output data for estimating the matrices
            of a linear time-invariant dynamical system, using Cholesky or
            (fast) QR factorization and subspace identification techniques
            (MOESP or N4SID), and estimates the system order.
        </para>
        <para>
            [R,N] = findR(S,Y,U,METH,ALG,JOBD,TOL,PRINTW)  returns the processed
            upper triangular factor  R  of the concatenated block-Hankel matrices
            built from the input-output data, and the order  N  of a discrete-time
            realization. The model structure is:
        </para>
        <programlisting role=""><![CDATA[
x(k+1) = Ax(k) + Bu(k) + w(k),   k >= 1,
y(k)   = Cx(k) + Du(k) + e(k).
 ]]></programlisting>
        <para>
            The vectors y(k) and u(k) are transposes of the k-th rows of Y and U,
            respectively.
        </para>
        <para>
            [R,N,SVAL,RCND] = findR(S,Y,U,METH,ALG,JOBD,TOL,PRINTW)  also returns
            the singular values SVAL, used for estimating the order, as well as,
            if meth = 2, the vector RCND of length 2 containing the reciprocal
            condition numbers of the matrices involved in rank decisions or least
            squares solutions.
        </para>
        <para>
            [R,N] = findR(S,Y)  assumes U = [] and default values for the
            remaining input arguments.
        </para>
    </refsection>
    <refsection>
        <title>Examples</title>
        <programlisting role="example"><![CDATA[
//generate data from a given linear system
A = [ 0.5, 0.1,-0.1, 0.2;
      0.1, 0,  -0.1,-0.1;
     -0.4,-0.6,-0.7,-0.1;
      0.8, 0,  -0.6,-0.6];
B = [0.8;0.1;1;-1];
C = [1 2 -1 0];
SYS=syslin(0.1,A,B,C);
U=(ones(1,1000)+rand(1,1000,'normal'));
Y=(flts(U,SYS)+0.5*rand(1,1000,'normal'));
// Compute R

[R,N,SVAL] = findR(15,Y',U');
SVAL
N
 ]]></programlisting>
    </refsection>
    <refsection role="see also">
        <title>See also</title>
        <simplelist type="inline">
            <member>
                <link linkend="findABCD">findABCD</link>
            </member>
            <member>
                <link linkend="findAC">findAC</link>
            </member>
            <member>
                <link linkend="findBD">findBD</link>
            </member>
            <member>
                <link linkend="findBDK">findBDK</link>
            </member>
            <member>
                <link linkend="sorder">sorder</link>
            </member>
            <member>
                <link linkend="sident">sident</link>
            </member>
        </simplelist>
    </refsection>
</refentry>
