<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<!DOCTYPE MAN SYSTEM "../../manrev.dtd">
<MAN>
  <LANGUAGE>eng</LANGUAGE>
  <TITLE>findBD</TITLE>
  <TYPE>Scilab Function</TYPE>
  <DATE>April 1999</DATE>
  <SHORT_DESCRIPTION name="findBD"> initial state and system matrices B and D of a discrete-time system</SHORT_DESCRIPTION>
  <CALLING_SEQUENCE>
    <CALLING_SEQUENCE_ITEM>[(x0) (,B (,D)) (,V) (,rcnd)] = findBD(jobx0,comuse (,job),A (,B),C (,D),Y</CALLING_SEQUENCE_ITEM>
    <CALLING_SEQUENCE_ITEM>                                      (,U,tol,printw,ldwork))  </CALLING_SEQUENCE_ITEM>
  </CALLING_SEQUENCE>
  <PARAM>
    <PARAM_INDENT>
      <PARAM_ITEM>
        <PARAM_NAME>jobx0</PARAM_NAME>
        <PARAM_DESCRIPTION>
          <SP>: integer option to specify whether or not the initial state  should be computed:</SP>
          <PARAM_INDENT>
            <PARAM_ITEM>
              <PARAM_NAME>=  </PARAM_NAME>
              <PARAM_DESCRIPTION>
                <SP>1 : compute the initial state x0;</SP>
              </PARAM_DESCRIPTION>
            </PARAM_ITEM>
            <PARAM_ITEM>
              <PARAM_NAME>=  </PARAM_NAME>
              <PARAM_DESCRIPTION>
                <SP>2 : do not compute the initial state (possibly, because x0 is known to be zero).</SP>
              </PARAM_DESCRIPTION>
            </PARAM_ITEM>
          </PARAM_INDENT>
        </PARAM_DESCRIPTION>
      </PARAM_ITEM>
      <PARAM_ITEM>
        <PARAM_NAME>comuse</PARAM_NAME>
        <PARAM_DESCRIPTION>
          <SP>: integer option to specify whether the system matrices B and D should be computed or used:</SP>
          <PARAM_INDENT>
            <PARAM_ITEM>
              <PARAM_NAME>=  </PARAM_NAME>
              <PARAM_DESCRIPTION>
                <SP>1 : compute the matrices B and D, as specified by job;</SP>
              </PARAM_DESCRIPTION>
            </PARAM_ITEM>
            <PARAM_ITEM>
              <PARAM_NAME>=  </PARAM_NAME>
              <PARAM_DESCRIPTION>
                <SP>2 : use the matrices B and D, as specified by job;</SP>
              </PARAM_DESCRIPTION>
            </PARAM_ITEM>
            <PARAM_ITEM>
              <PARAM_NAME>=  </PARAM_NAME>
              <PARAM_DESCRIPTION>
                <SP>3 : do not compute/use the matrices B and D.</SP>
              </PARAM_DESCRIPTION>
            </PARAM_ITEM>
          </PARAM_INDENT>
        </PARAM_DESCRIPTION>
      </PARAM_ITEM>
      <PARAM_ITEM>
        <PARAM_NAME>job</PARAM_NAME>
        <PARAM_DESCRIPTION>
          <SP>: integer option to determine which of the system matrices B and D should be computed or used:</SP>
          <PARAM_INDENT>
            <PARAM_ITEM>
              <PARAM_NAME>=  </PARAM_NAME>
              <PARAM_DESCRIPTION>
                <SP>1 : compute/use the matrix B only (D is known to be zero);</SP>
              </PARAM_DESCRIPTION>
            </PARAM_ITEM>
            <PARAM_ITEM>
              <PARAM_NAME>=  </PARAM_NAME>
              <PARAM_DESCRIPTION>
                <SP>2 : compute/use the matrices B and D.</SP>
              </PARAM_DESCRIPTION>
            </PARAM_ITEM>
          </PARAM_INDENT>
          <P>
    job must not be specified if jobx0 = 2 and comuse = 2, or if comuse = 3.
  </P>
        </PARAM_DESCRIPTION>
      </PARAM_ITEM>
      <PARAM_ITEM>
        <PARAM_NAME>A</PARAM_NAME>
        <PARAM_DESCRIPTION>
          <SP>: state matrix of the given system</SP>
        </PARAM_DESCRIPTION>
      </PARAM_ITEM>
      <PARAM_ITEM>
        <PARAM_NAME>B</PARAM_NAME>
        <PARAM_DESCRIPTION>
          <SP>: optionnal, input matrix of the given system</SP>
        </PARAM_DESCRIPTION>
      </PARAM_ITEM>
      <PARAM_ITEM>
        <PARAM_NAME>C</PARAM_NAME>
        <PARAM_DESCRIPTION>
          <SP>: output matrix of the given system</SP>
        </PARAM_DESCRIPTION>
      </PARAM_ITEM>
      <PARAM_ITEM>
        <PARAM_NAME>D</PARAM_NAME>
        <PARAM_DESCRIPTION>
          <SP>: optionnal, direct feedthrough of the given system</SP>
        </PARAM_DESCRIPTION>
      </PARAM_ITEM>
      <PARAM_ITEM>
        <PARAM_NAME>Y</PARAM_NAME>
        <PARAM_DESCRIPTION>
          <SP>: the t-by-l output-data sequence matrix.  Column  j  of  Y  contains the  t  values of the j-th output component for consecutive time increments.</SP>
        </PARAM_DESCRIPTION>
      </PARAM_ITEM>
      <PARAM_ITEM>
        <PARAM_NAME>U</PARAM_NAME>
        <PARAM_DESCRIPTION>
          <SP>: the t-by-m input-data sequence matrix (input when jobx0 = 1  and comuse = 2, or comuse = 1).  Column  j  of  U  contains the  t  values of the j-th input component for consecutive time increments.</SP>
        </PARAM_DESCRIPTION>
      </PARAM_ITEM>
      <PARAM_ITEM>
        <PARAM_NAME>tol</PARAM_NAME>
        <PARAM_DESCRIPTION>
          <SP>: optionnal, tolerance used for estimating the rank of
  matrices. If  tol &gt; 0,  then the given value of  tol  is used as
  a lower bound for the reciprocal condition number; an m-by-n matrix
  whose estimated condition number is less than  1/tol  is considered
  to be of full rank. Default:    m*n*epsilon_machine where
  epsilon_machine is the relative machine precision.</SP>
        </PARAM_DESCRIPTION>
      </PARAM_ITEM>
      <PARAM_ITEM>
        <PARAM_NAME>printw</PARAM_NAME>
        <PARAM_DESCRIPTION>
          <SP>:optionnal, switch for printing the warning messages.</SP>
          <PARAM_INDENT>
            <PARAM_ITEM>
              <PARAM_NAME>=  </PARAM_NAME>
              <PARAM_DESCRIPTION>
                <SP>1:  print warning messages;</SP>
              </PARAM_DESCRIPTION>
            </PARAM_ITEM>
            <PARAM_ITEM>
              <PARAM_NAME>=  </PARAM_NAME>
              <PARAM_DESCRIPTION>
                <SP>0:  do not print warning messages.</SP>
              </PARAM_DESCRIPTION>
            </PARAM_ITEM>
          </PARAM_INDENT>
          <P>
    Default:    printw = 0.
  </P>
        </PARAM_DESCRIPTION>
      </PARAM_ITEM>
      <PARAM_ITEM>
        <PARAM_NAME>ldwork</PARAM_NAME>
        <PARAM_DESCRIPTION>
          <SP>: (optional) the workspace size. Default :   computed by the formula LDWORK = MAX( minimum workspace size needed, 2*CSIZE/3, CSIZE - ( m + l )*t - 2*n*( n + m + l ) - l*m ) where CSIZE is the cache size in double precision words.</SP>
        </PARAM_DESCRIPTION>
      </PARAM_ITEM>
      <PARAM_ITEM>
        <PARAM_NAME>x0</PARAM_NAME>
        <PARAM_DESCRIPTION>
          <SP>: initial state vector</SP>
        </PARAM_DESCRIPTION>
      </PARAM_ITEM>
      <PARAM_ITEM>
        <PARAM_NAME>Br</PARAM_NAME>
        <PARAM_DESCRIPTION>
          <SP>: system input matrix</SP>
        </PARAM_DESCRIPTION>
      </PARAM_ITEM>
      <PARAM_ITEM>
        <PARAM_NAME>Dr</PARAM_NAME>
        <PARAM_DESCRIPTION>
          <SP>: system direct feedthrough matrix</SP>
        </PARAM_DESCRIPTION>
      </PARAM_ITEM>
      <PARAM_ITEM>
        <PARAM_NAME>V</PARAM_NAME>
        <PARAM_DESCRIPTION>
          <SP>: the n-by-n orthogonal matrix which reduces A to a real Schur form (output when jobx0 = 1 or comuse = 1).</SP>
        </PARAM_DESCRIPTION>
      </PARAM_ITEM>
      <PARAM_ITEM>
        <PARAM_NAME>rcnd</PARAM_NAME>
        <PARAM_DESCRIPTION>
          <SP>: (optional) the reciprocal condition numbers of the matrices involved in rank decisions.</SP>
        </PARAM_DESCRIPTION>
      </PARAM_ITEM>
    </PARAM_INDENT>
  </PARAM>
  <DESCRIPTION>
    <P>
    findBD  function for estimating the initial state and the system
    matrices B and D of a discrete-time system, using SLICOT routine 
    IB01CD.
  </P>
    <VERBATIM>
<![CDATA[

     [x0,Br,V,rcnd] = findBD(1,1,1,A,C,Y,U)
   [x0,Br,Dr,V,rcnd] = findBD(1,1,2,A,C,Y,U)
        [Br,V,rcnd] = findBD(2,1,1,A,C,Y,U)
      [B,Dr,V,rcnd] = findBD(2,1,2,A,C,Y,U)
       [x0,V,rcnd] = findBD(1,2,1,A,B,C,Y,U)
       [x0,V,rcnd] = findBD(1,2,2,A,B,C,D,Y,U)
         [x0,rcnd] = findBD(2,2)      // (Set x0 = 0, rcnd = 1)
       [x0,V,rcnd] = findBD(1,3,A,C,Y)
   ]]>
    </VERBATIM>
    <P>
    Note: the example lines above may contain at the end the parameters
    tol, printw, ldwork.
  </P>
    <P>
    FINDBD estimates the initial state and/or the system matrices Br and Dr
    of a discrete-time system, given the system matrices A, C, and possibly
    B, D, and the input and output trajectories of the system.
  </P>
    <P>
    The model structure is :
  </P>
    <VERBATIM>
<![CDATA[
         x(k+1) = Ax(k) + Bu(k),   k >= 1,
         y(k)   = Cx(k) + Du(k),
   ]]>
    </VERBATIM>
    <P>
       where 
     
    x(k)  is the  n-dimensional state vector (at time k),
  </P>
    <P>
    u(k)  is the  m-dimensional input vector,
  </P>
    <P>
    y(k)  is the  l-dimensional output vector,
  </P>
    <P>
    and  A, B, C, and D  are real matrices of appropriate dimensions.
  </P>
  </DESCRIPTION>
  <SECTION label="Comments">
    <ITEMIZE>
      <ITEM label="1.">
        <SP>The n-by-m system input matrix B is an input parameter when jobx0 = 1  and comuse = 2, and it is an output parameter when comuse = 1.</SP>
      </ITEM>
      <ITEM label="2.">
        <SP>The l-by-m system matrix D is an input parameter when jobx0 = 1,  comuse = 2 and job = 2, and it is an output parameter when comuse = 1  and job = 2.</SP>
      </ITEM>
      <ITEM label="3.">
        <SP>The n-vector of estimated initial state x(0) is an output parameter when jobx0 = 1, but also when jobx0 = 2 and comuse &lt;= 2, in which case it is set to 0.</SP>
      </ITEM>
      <ITEM label="4.">
        <SP>If ldwork is specified, but it is less than the minimum workspace size  needed, that minimum value is used instead.</SP>
      </ITEM>
    </ITEMIZE>
  </SECTION>
  <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);
nsmp=100;
U=prbs_a(nsmp,nsmp/5);
Y=(flts(U,SYS)+0.3*rand(1,nsmp,'normal'));

// Compute R
S=15;L=1;
[R,N,SVAL] = findR(S,Y',U');

N=3;
METH=3;TOL=-1;
[A,C] = findAC(S,N,L,R,METH,TOL);
[X0,B,D] = findBD(1,1,2,A,C,Y',U')
SYS1=syslin(1,A,B,C,D,X0);

Y1=flts(U,SYS1);
xbasc();plot2d((1:nsmp)',[Y',Y1'])
 ]]>
  </EXAMPLE>
  <SEE_ALSO>
    <SEE_ALSO_ITEM>
      <LINK>inistate</LINK>
    </SEE_ALSO_ITEM>
    <SEE_ALSO_ITEM>
      <LINK>findx0BD</LINK>
    </SEE_ALSO_ITEM>
    <SEE_ALSO_ITEM>
      <LINK>findABCD</LINK>
    </SEE_ALSO_ITEM>
    <SEE_ALSO_ITEM>
      <LINK>findAC</LINK>
    </SEE_ALSO_ITEM>
    <SEE_ALSO_ITEM>
      <LINK>findBD</LINK>
    </SEE_ALSO_ITEM>
  </SEE_ALSO>
  <AUTHOR>V. Sima, Katholieke Univ. Leuven, Belgium, May 2000.  
  (Revisions: V. Sima, July 2000)</AUTHOR>
</MAN>
