% ddom1 - a script that determines if the matrix A is diagonally dominant. % If it isn't, then the matrix is modified so that it is diagonally dominant. % See ddom2.m for an equivalent function. % % MATLAB Primer, 6th Edition % Kermit Sigmon and Timothy A. Davis % Section 7.2, page 35. 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 ; tol = 100 * eps ; s = 2 * (d (i) >= 0) - 1 ; A (k) = (1+tol) * s .* max (f (i), tol) ;