/* nag_real_qr (f01qcc) Example Program. * * Copyright 1990 Numerical Algorithms Group. * * Mark 1, 1990. * Mark 8 revised, 2004. */ #include #include #include #include #define A(I, J) a[(I) *tda + J] int main(void) { Integer exit_status = 0, i, j, m, n, tda; NagError fail; double *a = 0, *zeta = 0; INIT_FAIL(fail); printf("nag_real_qr (f01qcc) Example Program Results\n"); scanf(" %*[^\n]"); /* skip headings in data file */ scanf(" %*[^\n]"); scanf("%ld%ld", &m, &n); if (n >= 0 && m >= n) { if (!(zeta = NAG_ALLOC(n, double)) || !(a = NAG_ALLOC(m*n, double))) { printf("Allocation failure\n"); exit_status = -1; goto END; } tda = n; } else { printf("Invalid n or m.\n"); exit_status = 1; return exit_status; } scanf(" %*[^\n]"); /* skip next heading */ for (i = 0; i < m; ++i) /* Read matrix A */ for (j = 0; j < n; ++j) scanf("%lf", &A(i, j)); /* Find the QR factorization of A */ /* nag_real_qr (f01qcc). * QR factorization of real m by n matrix (m >= n) */ nag_real_qr(m, n, a, tda, zeta, &fail); if (fail.code != NE_NOERROR) { printf("Error from nag_real_qr (f01qcc).\n%s\n", fail.message); exit_status = 1; goto END; } printf("QR factorization of A\n\n"); printf("Vector zeta\n"); for (i = 0; i < n; ++i) printf(" %8.4f", zeta[i]); printf("\n\n"); printf("Matrix A after factorization (upper triangular part is R)\n"); for (i = 0; i < m; ++i) { for (j = 0; j < n; ++j) printf(" %8.4f", A(i, j)); printf("\n"); } END: NAG_FREE(zeta); NAG_FREE(a); return exit_status; }