home *** CD-ROM | disk | FTP | other *** search
- //-------------------------------------------------------------------//
-
- // Synopsis: Comparison matrices.
-
- // Syntax: comp ( A )
-
- // Description:
-
- // COMP(A) is diag(B) - tril(B,-1) - triu(B,1), where B =
- // abs(A). COMP(A, 1) is A with each diagonal element replaced by
- // its absolute value, and each off-diagonal element replaced by
- // minus the absolute value of the largest element in absolute
- // value in its row. However, if A is triangular COMP(A, 1) is
- // too. COMP(A, 0) is the same as COMP(A). COMP(A) is often
- // denoted by M(A) in the literature.
-
- // Reference (e.g.):
- // N.J. Higham, A survey of condition number estimation for
- // triangular matrices, SIAM Review, 29 (1987), pp. 575-596.
-
- // This file is a translation of comp.m from version 2.0 of
- // "The Test Matrix Toolbox for Matlab", described in Numerical
- // Analysis Report No. 237, December 1993, by N. J. Higham.
-
- //-------------------------------------------------------------------//
-
- comp = function (A, k)
- {
- local (A, k)
-
- if (!exist (k)) { k = 0; }
-
- m = A.nr; n = A.nc;
- p = min(m, n);
-
- if (k == 0)
- {
- // This code uses less temporary storage than
- // the `high level' definition above.
-
- C = -abs(A);
- for (j in 1:p)
- {
- C[j;j] = abs(A[j;j]);
- }
-
- else if (k == 1) {
-
- C = A';
- for (j in 1:p)
- {
- C[k;k] = 0;
- }
- mx = max (abs (C));
- C = -mx'*ones(1,n);
- for (j in 1:p)
- {
- C[j;j] = abs(A[j;j]);
- }
- if (all (A == tril(A))) { C = tril(C); }
- if (all (A == triu(A))) { C = triu(C); }
-
- } }
-
- return C;
- };
-
-