comparison toolbox/comp.m @ 2:c124219d7bfa draft

Re-add the 1995 toolbox after noticing the statement in the ~higham/mctoolbox/ webpage.
author Antonio Pino Robles <data.script93@gmail.com>
date Thu, 07 May 2015 18:36:24 +0200
parents 8f23314345f4
children
comparison
equal deleted inserted replaced
1:e471a92d17be 2:c124219d7bfa
1 function C = comp(A, k)
2 %COMP Comparison matrices.
3 % COMP(A) is DIAG(B) - TRIL(B,-1) - TRIU(B,1), where B = ABS(A).
4 % COMP(A, 1) is A with each diagonal element replaced by its
5 % absolute value, and each off-diagonal element replaced by minus
6 % the absolute value of the largest element in absolute value in
7 % its row. However, if A is triangular COMP(A, 1) is too.
8 % COMP(A, 0) is the same as COMP(A).
9 % COMP(A) is often denoted by M(A) in the literature.
10
11 % Reference (e.g.):
12 % N.J. Higham, A survey of condition number estimation for
13 % triangular matrices, SIAM Review, 29 (1987), pp. 575-596.
14
15 if nargin == 1, k = 0; end
16 [m, n] = size(A);
17 p = min(m, n);
18
19 if k == 0
20
21 % This code uses less temporary storage than the `high level' definition above.
22 C = -abs(A);
23 for j=1:p
24 C(j,j) = abs(A(j,j));
25 end
26
27 elseif k == 1
28
29 C = A';
30 for j=1:p
31 C(k,k) = 0;
32 end
33 mx = max(abs(C));
34 C = -mx'*ones(1,n);
35 for j=1:p
36 C(j,j) = abs(A(j,j));
37 end
38 if all( A == tril(A) ), C = tril(C); end
39 if all( A == triu(A) ), C = triu(C); end
40
41 end