function [B,i] = ddom4 (A,tol) % %DDOM4 % % [B, i] = ddom4 (A, tol) % % DDOM4 returns a diagonally dominant matrix B by modifying the % diagonal of A. If row i violates diagonal dominance, then A(i,i) is % modified by setting it so that its absolute value is (1+tol)*f, where % f is the sum of the absolute values of the off-diagonal entries in row i % (assuming f is large enough). If f is smaller than tol, then the absolute % value of A(i,i) is set to (1+tol)*tol. The sign of A(i,i) is preserved. % The input argument tol is optional; if not present, a default value of % 100*eps is used. The outputs are B (the modified matrix) and a vector i % that contains a list of the row indices of the rows that violated % diagonal dominance. % % MATLAB Primer, 6th Edition % Kermit Sigmon and Timothy A. Davis % Section 7.6, page 38. d = diag (A) ; a = abs (d) ; f = sum (abs (A), 2) - a ; i = find (f >= a) ; [m n] = size (A) ; k = i + (i-1)*m ; if (nargin == 1) tol = 100 * eps ; end s = 2 * (d (i) >= 0) - 1 ; A (k) = (1+tol) * s .* max (f (i), tol) ; B = A ;