**Purpose**

1. To compute the triangular (QR) factor of the p-by-L*s structured matrix Q, [ Q_1s Q_1,s-1 Q_1,s-2 ... Q_12 Q_11 ] [ 0 Q_1s Q_1,s-1 ... Q_13 Q_12 ] Q = [ 0 0 Q_1s ... Q_14 Q_13 ], [ : : : : : ] [ 0 0 0 ... 0 Q_1s ] and apply the transformations to the p-by-m matrix Kexpand, [ K_1 ] [ K_2 ] Kexpand = [ K_3 ], [ : ] [ K_s ] where, for MOESP approach (METH = 'M'), p = s*(L*s-n), and Q_1i = u2(L*(i-1)+1:L*i,:)' is (Ls-n)-by-L, for i = 1:s, u2 = Un(1:L*s,n+1:L*s), K_i = K(:,(i-1)*m+1:i*m) (i = 1:s) is (Ls-n)-by-m, and for N4SID approach (METH = 'N'), p = s*(n+L), and [ -L_1|1 ] [ M_i-1 - L_1|i ] Q_11 = [ ], Q_1i = [ ], i = 2:s, [ I_L - L_2|1 ] [ -L_2|i ] are (n+L)-by-L matrices, and K_i = K(:,(i-1)*m+1:i*m), i = 1:s, is (n+L)-by-m. The given matrices are: For METH = 'M', u2 = Un(1:L*s,n+1:L*s), K(1:Ls-n,1:m*s); [ L_1|1 ... L_1|s ] For METH = 'N', L = [ ], (n+L)-by-L*s, [ L_2|1 ... L_2|s ] M = [ M_1 ... M_s-1 ], n-by-L*(s-1), and K, (n+L)-by-m*s. Matrix M is the pseudoinverse of the matrix GaL, built from the first n relevant singular vectors, GaL = Un(1:L(s-1),1:n), and computed by SLICOT Library routine IB01PD for METH = 'N'. Matrix Q is triangularized (in R), exploiting its structure, and the transformations are applied from the left to Kexpand. 2. To estimate the matrices B and D of a linear time-invariant (LTI) state space model, using the factor R, transformed matrix Kexpand, and the singular value decomposition information provided by other routines. IB01PY routine is intended for speed and efficient use of the memory space. It is generally not recommended for METH = 'N', as IB01PX routine can produce more accurate results.

SUBROUTINE IB01PY( METH, JOB, NOBR, N, M, L, RANKR1, UL, LDUL, $ R1, LDR1, TAU1, PGAL, LDPGAL, K, LDK, R, LDR, $ H, LDH, B, LDB, D, LDD, TOL, IWORK, DWORK, $ LDWORK, IWARN, INFO ) C .. Scalar Arguments .. DOUBLE PRECISION TOL INTEGER INFO, IWARN, L, LDB, LDD, LDH, LDK, LDPGAL, $ LDR, LDR1, LDUL, LDWORK, M, N, NOBR, RANKR1 CHARACTER JOB, METH C .. Array Arguments .. DOUBLE PRECISION B(LDB, *), D(LDD, *), DWORK(*), H(LDH, *), $ K(LDK, *), PGAL(LDPGAL, *), R(LDR, *), $ R1(LDR1, *), TAU1(*), UL(LDUL, *) INTEGER IWORK( * )

**Mode Parameters**

METH CHARACTER*1 Specifies the subspace identification method to be used, as follows: = 'M': MOESP algorithm with past inputs and outputs; = 'N': N4SID algorithm. JOB CHARACTER*1 Specifies whether or not the matrices B and D should be computed, as follows: = 'B': compute the matrix B, but not the matrix D; = 'D': compute both matrices B and D; = 'N': do not compute the matrices B and D, but only the R factor of Q and the transformed Kexpand.

NOBR (input) INTEGER The number of block rows, s, in the input and output Hankel matrices processed by other routines. NOBR > 1. N (input) INTEGER The order of the system. NOBR > N > 0. M (input) INTEGER The number of system inputs. M >= 0. L (input) INTEGER The number of system outputs. L > 0. RANKR1 (input) INTEGER The effective rank of the upper triangular matrix r1, i.e., the triangular QR factor of the matrix GaL, computed by SLICOT Library routine IB01PD. It is also the effective rank of the matrix GaL. 0 <= RANKR1 <= N. If JOB = 'N', or M = 0, or METH = 'N', this parameter is not used. UL (input/workspace) DOUBLE PRECISION array, dimension ( LDUL,L*NOBR ) On entry, if METH = 'M', the leading L*NOBR-by-L*NOBR part of this array must contain the matrix Un of relevant singular vectors. The first N columns of UN need not be specified for this routine. On entry, if METH = 'N', the leading (N+L)-by-L*NOBR part of this array must contain the given matrix L. On exit, the leading LDF-by-L*(NOBR-1) part of this array is overwritten by the matrix F of the algorithm in [4], where LDF = MAX( 1, L*NOBR-N-L ), if METH = 'M'; LDF = N, if METH = 'N'. LDUL INTEGER The leading dimension of the array UL. LDUL >= L*NOBR, if METH = 'M'; LDUL >= N+L, if METH = 'N'. R1 (input) DOUBLE PRECISION array, dimension ( LDR1,N ) If JOB <> 'N', M > 0, METH = 'M', and RANKR1 = N, the leading L*(NOBR-1)-by-N part of this array must contain details of the QR factorization of the matrix GaL, as computed by SLICOT Library routine IB01PD. Specifically, the leading N-by-N upper triangular part must contain the upper triangular factor r1 of GaL, and the lower L*(NOBR-1)-by-N trapezoidal part, together with array TAU1, must contain the factored form of the orthogonal matrix Q1 in the QR factorization of GaL. If JOB = 'N', or M = 0, or METH = 'N', or METH = 'M' and RANKR1 < N, this array is not referenced. LDR1 INTEGER The leading dimension of the array R1. LDR1 >= L*(NOBR-1), if JOB <> 'N', M > 0, METH = 'M', and RANKR1 = N; LDR1 >= 1, otherwise. TAU1 (input) DOUBLE PRECISION array, dimension ( N ) If JOB <> 'N', M > 0, METH = 'M', and RANKR1 = N, this array must contain the scalar factors of the elementary reflectors used in the QR factorization of the matrix GaL, computed by SLICOT Library routine IB01PD. If JOB = 'N', or M = 0, or METH = 'N', or METH = 'M' and RANKR1 < N, this array is not referenced. PGAL (input) DOUBLE PRECISION array, dimension ( LDPGAL,L*(NOBR-1) ) If METH = 'N', or JOB <> 'N', M > 0, METH = 'M' and RANKR1 < N, the leading N-by-L*(NOBR-1) part of this array must contain the pseudoinverse of the matrix GaL, as computed by SLICOT Library routine IB01PD. If METH = 'M' and JOB = 'N', or M = 0, or RANKR1 = N, this array is not referenced. LDPGAL INTEGER The leading dimension of the array PGAL. LDPGAL >= N, if METH = 'N', or JOB <> 'N', M > 0, and METH = 'M' and RANKR1 < N; LDPGAL >= 1, otherwise. K (input/output) DOUBLE PRECISION array, dimension ( LDK,M*NOBR ) On entry, the leading (p/s)-by-M*NOBR part of this array must contain the given matrix K defined above. On exit, the leading (p/s)-by-M*NOBR part of this array contains the transformed matrix K. LDK INTEGER The leading dimension of the array K. LDK >= p/s. R (output) DOUBLE PRECISION array, dimension ( LDR,L*NOBR ) If JOB = 'N', or M = 0, or Q has full rank, the leading L*NOBR-by-L*NOBR upper triangular part of this array contains the R factor of the QR factorization of the matrix Q. If JOB <> 'N', M > 0, and Q has not a full rank, the leading L*NOBR-by-L*NOBR upper trapezoidal part of this array contains details of the complete orhogonal factorization of the matrix Q, as constructed by SLICOT Library routines MB03OD and MB02QY. LDR INTEGER The leading dimension of the array R. LDR >= L*NOBR. H (output) DOUBLE PRECISION array, dimension ( LDH,M ) If JOB = 'N' or M = 0, the leading L*NOBR-by-M part of this array contains the updated part of the matrix Kexpand corresponding to the upper triangular factor R in the QR factorization of the matrix Q. If JOB <> 'N', M > 0, and METH = 'N' or METH = 'M' and RANKR1 < N, the leading L*NOBR-by-M part of this array contains the minimum norm least squares solution of the linear system Q*X = Kexpand, from which the matrices B and D are found. The first NOBR-1 row blocks of X appear in the reverse order in H. If JOB <> 'N', M > 0, METH = 'M' and RANKR1 = N, the leading L*(NOBR-1)-by-M part of this array contains the matrix product Q1'*X, and the subarray L*(NOBR-1)+1:L*NOBR-by-M contains the corresponding submatrix of X, with X defined in the phrase above. LDH INTEGER The leading dimension of the array H. LDH >= L*NOBR. B (output) DOUBLE PRECISION array, dimension ( LDB,M ) If M > 0, JOB = 'B' or 'D' and INFO = 0, the leading N-by-M part of this array contains the system input matrix. If M = 0 or JOB = 'N', this array is not referenced. LDB INTEGER The leading dimension of the array B. LDB >= N, if M > 0 and JOB = 'B' or 'D'; LDB >= 1, if M = 0 or JOB = 'N'. D (output) DOUBLE PRECISION array, dimension ( LDD,M ) If M > 0, JOB = 'D' and INFO = 0, the leading L-by-M part of this array contains the system input-output matrix. If M = 0 or JOB = 'B' or 'N', this array is not referenced. LDD INTEGER The leading dimension of the array D. LDD >= L, if M > 0 and JOB = 'D'; LDD >= 1, if M = 0 or JOB = 'B' or 'N'.

TOL DOUBLE PRECISION The tolerance to be used for estimating the rank of matrices. If the user sets TOL > 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. If the user sets TOL <= 0, then an implicitly computed, default tolerance, defined by TOLDEF = m*n*EPS, is used instead, where EPS is the relative machine precision (see LAPACK Library routine DLAMCH). This parameter is not used if M = 0 or JOB = 'N'.

IWORK INTEGER array, dimension ( LIWORK ) where LIWORK >= 0, if JOB = 'N', or M = 0; LIWORK >= L*NOBR, if JOB <> 'N', and M > 0. DWORK DOUBLE PRECISION array, dimension ( LDWORK ) On exit, if INFO = 0, DWORK(1) returns the optimal value of LDWORK, and, if JOB <> 'N', and M > 0, DWORK(2) contains the reciprocal condition number of the triangular factor of the matrix R. On exit, if INFO = -28, DWORK(1) returns the minimum value of LDWORK. LDWORK INTEGER The length of the array DWORK. LDWORK >= MAX( 2*L, L*NOBR, L+M*NOBR ), if JOB = 'N', or M = 0; LDWORK >= MAX( L+M*NOBR, L*NOBR + MAX( 3*L*NOBR+1, M ) ), if JOB <> 'N', and M > 0. For good performance, LDWORK should be larger.

IWARN INTEGER = 0: no warning; = 4: the least squares problem to be solved has a rank-deficient coefficient matrix.

INFO INTEGER = 0: successful exit; < 0: if INFO = -i, the i-th argument had an illegal value; = 3: a singular upper triangular matrix was found.

The QR factorization is computed exploiting the structure, as described in [4]. The matrices B and D are then obtained by solving certain linear systems in a least squares sense.

[1] Verhaegen M., and Dewilde, P. Subspace Model Identification. Part 1: The output-error state-space model identification class of algorithms. Int. J. Control, 56, pp. 1187-1210, 1992. [2] Van Overschee, P., and De Moor, B. N4SID: Two Subspace Algorithms for the Identification of Combined Deterministic-Stochastic Systems. Automatica, Vol.30, No.1, pp. 75-93, 1994. [3] Van Overschee, P. Subspace Identification : Theory - Implementation - Applications. Ph. D. Thesis, Department of Electrical Engineering, Katholieke Universiteit Leuven, Belgium, Feb. 1995. [4] Sima, V. Subspace-based Algorithms for Multivariable System Identification. Studies in Informatics and Control, 5, pp. 335-344, 1996.

The implemented method for computing the triangular factor and updating Kexpand is numerically stable.

The computed matrices B and D are not the least squares solutions delivered by either MOESP or N4SID algorithms, except for the special case n = s - 1, L = 1. However, the computed B and D are frequently good enough estimates, especially for METH = 'M'. Better estimates could be obtained by calling SLICOT Library routine IB01PX, but it is less efficient, and requires much more workspace.

**Program Text**

None

None

None