/* nag_superlu_matrix_norm (f11mlc) Example Program. * * Copyright 2005 Numerical Algorithms Group. * * Mark 8, 2005. */ #include #include #include #include int main(void) { double anorm; Integer exit_status=0, i, n, nnz; double *a=0; Integer *icolzp=0, *irowix=0; /* Nag types */ NagError fail; Nag_NormType norm; INIT_FAIL(fail); Vprintf( "nag_superlu_matrix_norm (f11mlc) Example Program Results\n\n"); /* Skip heading in data file */ Vscanf("%*[^\n] "); /* Read order of matrix and number of right hand sides */ Vscanf("%ld%*[^\n] ", &n); /* Read the matrix A */ if ( !(icolzp = NAG_ALLOC(n+1, Integer))) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } for (i = 1; i <= n + 1; ++i) Vscanf("%ld%*[^\n] ", &icolzp[i - 1]); nnz = icolzp[n] - 1; /* Allocate memory */ if ( !(a = NAG_ALLOC(nnz, double)) || !(irowix = NAG_ALLOC(nnz, Integer)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } for (i = 1; i <= nnz; ++i) Vscanf("%lf%ld%*[^\n] ", &a[i - 1], &irowix[i - 1]); /* Calculate 1-norm */ norm = Nag_RealOneNorm; /* nag_superlu_matrix_norm (f11mlc). * 1-norm, infinity-norm, largest absolute element, real * general matrix */ nag_superlu_matrix_norm(norm, &anorm, n, icolzp, irowix, a, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_superlu_matrix_norm (f11mlc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Output norm */ Vprintf("%s\n%7.3f\n", "One-norm", anorm); /* Calculate M-norm */ norm = Nag_RealMaxNorm; /* nag_superlu_matrix_norm (f11mlc), see above. */ nag_superlu_matrix_norm(norm, &anorm, n, icolzp, irowix, a, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_superlu_matrix_norm (f11mlc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Output norm */ Vprintf("\n"); Vprintf("%s\n%7.3f\n", "Max", anorm); /* Calculate I-norm */ norm = Nag_RealInfNorm; /* nag_superlu_matrix_norm (f11mlc), see above. */ nag_superlu_matrix_norm(norm, &anorm, n, icolzp, irowix, a, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_superlu_matrix_norm (f11mlc).\n%s\n", fail.message); exit_status = 1; goto END; } /* Output norm */ Vprintf("\n"); Vprintf("%s\n%7.3f\n", "Infinity-norm", anorm); END: if (a) NAG_FREE(a); if (icolzp) NAG_FREE(icolzp); if (irowix) NAG_FREE(irowix); return exit_status; }