/* nag_dgb_norm (f16rbc) Example Program. * * Copyright 2005 Numerical Algorithms Group. * * Mark 8, 2005. */ #include #include #include #include #include int main(void) { /* Scalars */ double r_one, r_inf, r_f, r_max; Integer ab_size, exit_status, i, j, kl, ku; Integer m, n, pdab; /* Arrays */ double *ab=0; /* Nag Types */ NagError fail; Nag_OrderType order; #ifdef NAG_COLUMN_MAJOR #define AB(I,J) ab[(J-1)*pdab + ku + I - J] order = Nag_ColMajor; #else #define AB(I,J) ab[(I-1)*pdab + kl + J - I] order = Nag_RowMajor; #endif exit_status = 0; INIT_FAIL(fail); Vprintf( "nag_dgb_norm (f16rbc) Example Program Results\n\n"); /* Skip heading in data file */ Vscanf("%*[^\n] "); /* Read the problem dimensions */ Vscanf("%ld%ld%ld%ld%*[^\n] ", &m, &n, &kl, &ku); pdab = kl + ku + 1; #ifdef NAG_COLUMN_MAJOR ab_size = pdab*n; #else ab_size = pdab*m; #endif if (m > 0 && n > 0) { /* Allocate memory */ if ( !(ab = NAG_ALLOC(ab_size, double)) ) { Vprintf("Allocation failure\n"); exit_status = -1; goto END; } } else { Vprintf("Invalid m or n\n"); exit_status = 1; return exit_status; } /* Input matrix A. */ for (i = 1; i <= m; ++i) { for (j = MAX(1,i-kl); j <= MIN(n,i+ku); ++j) Vscanf("%lf", &AB(i,j)); Vscanf("%*[^\n] "); } /* nag_dgb_norm(f16rbc). * calculates norm of real valued general band matrix. * */ nag_dgb_norm(order, Nag_OneNorm, m, n, kl, ku, ab, pdab, &r_one, &fail); nag_dgb_norm(order, Nag_InfNorm, m, n, kl, ku, ab, pdab, &r_inf, &fail); nag_dgb_norm(order, Nag_FrobeniusNorm, m, n, kl, ku, ab, pdab, &r_f, &fail); nag_dgb_norm(order, Nag_MaxNorm, m, n, kl, ku, ab, pdab, &r_max, &fail); if (fail.code != NE_NOERROR) { Vprintf("Error from nag_dgb_norm.\n%s\n", fail.message); exit_status = 1; goto END; } /* Print norms of A. */ Vprintf(" Norms of banded matrix A:\n\n"); Vprintf(" One norm = %7.4f\n", r_one); Vprintf(" Infinity norm = %7.4f\n", r_inf); Vprintf(" Frobenius norm = %7.4f\n", r_f); Vprintf(" Maximum norm = %7.4f\n", r_max); END: if (ab) NAG_FREE(ab); return exit_status; }