/* nag_real_apply_q (f01qdc) 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] #define B(I, J) b[(I) *tdb + J] int main(void) { Integer exit_status = 0, i, j, m, n, ncolb, tda, tdb; NagError fail; double *a = 0, *b = 0, *zeta = 0; INIT_FAIL(fail); printf("nag_real_apply_q (f01qdc) Example Program Results\n"); scanf(" %*[^\n]"); /* skip headings in data file */ scanf(" %*[^\n]"); scanf("%ld%ld", &m, &n); if (n > 0 && m >= n) { if (!(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]"); for (i = 0; i < m; ++i) for (j = 0; j < n; ++j) scanf("%lf", &A(i, j)); scanf(" %*[^\n]"); scanf("%ld", &ncolb); if (ncolb >= 0) { if (!(zeta = NAG_ALLOC(n, double)) || !(b = NAG_ALLOC(m*ncolb, double))) { printf("Allocation failure\n"); exit_status = -1; goto END; } tdb = ncolb; } else { printf("Invalid ncolb.\n"); exit_status = 1; return exit_status; } scanf(" %*[^\n]"); for (i = 0; i < m; ++i) for (j = 0; j < ncolb; ++j) scanf("%lf", &B(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; } /* Form Q'*B */ /* nag_real_apply_q (f01qdc). * Compute QB or Q^TB after factorization by nag_real_qr * (f01qcc) */ nag_real_apply_q(Transpose, Nag_ElementsSeparate, m, n, a, tda, zeta, ncolb, b, tdb, &fail); if (fail.code != NE_NOERROR) { printf("Error from nag_real_apply_q (f01qdc).\n%s\n", fail.message); exit_status = 1; goto END; } printf("Matrix Q'*B\n"); for (i = 0; i < m; ++i) { for (j = 0; j < ncolb; ++j) printf(" %8.4f", B(i, j)); printf("\n"); } END: if (a) NAG_FREE(a); if (zeta) NAG_FREE(zeta); if (b) NAG_FREE(b); return exit_status; }