/* nag_trans_hessenberg_observer(g13ewc) Example Program * * Copyright 1993 Numerical Algorithms Group * * Mark 3, 1993 */ #include #include #include #include #define NMAX 20 #define PMAX 20 #define TDA NMAX #define TDC NMAX #define TDU NMAX int main(void) { double a[NMAX][TDA]; double c[PMAX][TDC]; double u[NMAX][TDU]; Integer i, j, n, p; Nag_ObserverForm reduceto; double zero = 0.0, one = 1.0; Integer nmax, pmax; Vprintf("g13ewc Example Program Results\n"); /* Skip the heading in the data file and read the data. */ Vscanf("%*[^\n]"); nmax = NMAX; pmax = PMAX; Vscanf("%ld%ld",&n,&p); if (n<=0 || p<=0 || n>nmax || p>pmax) { Vfprintf(stderr,"One of n or p is out of range n = %ld, p = %ld\n", n, p); return EXIT_FAILURE; } reduceto = Nag_UH_Observer; for (j = 0; j < n; ++j) for (i = 0; i < n; ++i) Vscanf("%lf", &a[i][j]); for (i = 0; i < p; ++i) for (j = 0; j < n; ++j) Vscanf("%lf", &c[i][j]); if (u) /* Initialise U as the identity matrix. */ for (i = 0; i < n; ++i) { for (j = 0; j < n; ++j) u[i][j] = zero; u[i][i] = one; } /* Reduce the pair (A,C) to reduceto observer Hessenberg form. */ g13ewc(n, p, reduceto, &a[0][0], (Integer)TDA, &c[0][0], (Integer)TDC, &u[0][0], (Integer)TDU, NAGERR_DEFAULT); Vprintf("\nThe transformed state transition matrix is \n\n"); for (i = 0; i < n; ++i) { for (j = 0; j < n; ++j) Vprintf("%8.4f ",a[i][j]); Vprintf("\n"); } Vprintf("\nThe transformed input matrix is \n\n"); for (i = 0; i < p; ++i) { for (j = 0; j < n; ++j) Vprintf("%8.4f ",c[i][j]); Vprintf("\n"); } if (u) { Vprintf("\nThe transformation matrix that reduces (A,C) " "to observer Hessenberg form is \n\n"); for (i = 0; i < n; ++i) { for (j = 0; j < n; ++j) Vprintf("%8.4f ",u[i][j]); Vprintf("\n"); } } return EXIT_SUCCESS; }