/* nag_kalman_sqrt_filt_cov_invar (g13ebc) Example Program. * * Copyright 1993 Numerical Algorithms Group * * Mark 3, 1993 * Mark 7, revised, 2001. * Mark 8 revised, 2004. * */ #include #include #include #include #include #include typedef enum {read, print} ioflag; static int ex1(void); static int ex2(void); int main(void) { Integer exit_status_ex1=0; Integer exit_status_ex2=0; exit_status_ex1 = ex1(); exit_status_ex2 = ex2(); return exit_status_ex1 == 0 && exit_status_ex2 == 0 ? 0 : 1; } #define A(I,J) a[(I)*tda + J] #define B(I,J) b[(I)*tdb + J] #define C(I,J) c[(I)*tdc + J] #define K(I,J) k[(I)*tdk + J] #define Q(I,J) q[(I)*tdq + J] #define R(I,J) r[(I)*tdr + J] #define S(I,J) s[(I)*tds + J] #define H(I,J) h[(I)*tdh + J] static int ex1(void) { /* simple example (matrices A and C are supplied in lower observer Hessenberg form) */ Integer exit_status=0, i, istep, j, m, n, p, tda, tdb, tdc, tdh, tdk, tdq; Integer tdr, tds; NagError fail; double *a=0, *b=0, *c=0, *h=0, *k=0, *q=0, *r=0, *s=0, tol; INIT_FAIL(fail); Vprintf("nag_kalman_sqrt_filt_cov_invar (g13ebc) Example 1 Program " "Results\n"); /* Skip the heading in the data file */ Vscanf(" %*[^\n]"); Vscanf("%ld%ld%ld%lf",&n,&m,&p,&tol); if (n>=1 && m>=1 && p>=1) { if ( !( a = NAG_ALLOC(n*n, double)) || !( b = NAG_ALLOC(n*m, double)) || !( c = NAG_ALLOC(p*n, double)) || !( k = NAG_ALLOC(n*p, double)) || !( q = NAG_ALLOC(m*m, double)) || !( r = NAG_ALLOC(p*p, double)) || !( s = NAG_ALLOC(n*n, double)) || !( h = NAG_ALLOC(n*p, double)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } tda = n; tdb = m; tdc = n; tdk = p; tdq = m; tdr = p; tds = n; tdh = p; } else { Vprintf("Invalid n or m or p.\n"); exit_status = 1; return exit_status; } /* Read data */ for (i=0; i=1 && m>=1 && p>=1) { if ( !( a = NAG_ALLOC(n*n, double)) || !( b = NAG_ALLOC(n*m, double)) || !( c = NAG_ALLOC(p*n, double)) || !( ke = NAG_ALLOC(n*p, double)) || !( kf = NAG_ALLOC(n*p, double)) || !( ub = NAG_ALLOC(n*m, double)) || !( q = NAG_ALLOC(m*m, double)) || !( r = NAG_ALLOC(p*p, double)) || !( rwork = NAG_ALLOC(n*n, double)) || !( sf = NAG_ALLOC(n*n, double)) || !( se = NAG_ALLOC(n*n, double)) || !( h = NAG_ALLOC(n*p, double)) || !( pf = NAG_ALLOC(n*n, double)) || !( pe = NAG_ALLOC(n*n, double)) || !( uaut = NAG_ALLOC(n*n, double)) || !( cut = NAG_ALLOC(p*n, double)) || !( u = NAG_ALLOC(n*n, double)) || !( diag = NAG_ALLOC(n, double)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } tda = n; tdb = m; tdc = n; tdke = p; tdkf = p; tdub = m; tdq = m; tdr = p; tdrwork = n; tdsf = n; tdse = n; tdh = p; tdpf = n; tdpe = n; tduaut = n; tdcut = n; tdu = n; } else { Vprintf("Invalid n or m or p.\n"); exit_status = 1; return exit_status; } mat_io(n, n, se, tdse, read, ""); mat_io(n, n, a, tda, read, ""); mat_io(n, m, b, tdb, read, ""); if (q) mat_io(m, m, q, tdq, read,""); mat_io(p, n, c, tdc, read, ""); mat_io(p, p, r, tdr, read, ""); for (i=0; i