tags:

views:

89

answers:

2

A matrix is diagonally dominant (by rows) if its value at the diagonal is greater then the sum of all absolute value in that row. Same goes for columns, only the other way around.

Is there a function in matlab for chekcing this ? (I could write a simple loop, but I'm trying to quit those).

+3  A: 

Why loop?

You can easily form the sum of absolute values in a given row.

sum(abs(A),2)

Can you compare this to the absolute diagonal elements in each row?

abs(diag(A)) >= sum(abs(A),2)

Of course, this is not correct, since the diagonal terms should not be included in the first sum. Regardless, we can easily repair the problem.

(2*abs(diag(A))) >= sum(abs(A),2)

Finally, we need a result from this test. The above tests each row. A matrix is diagonally dominant if that test is true for ALL rows.

all((2*abs(diag(A))) >= sum(abs(A),2))
woodchips
+2  A: 

There is no function that I know of. However, you can make a simple test without loops.

%# create an array
array = magic(3);

%# take the absolute of the array
absArray = abs(array);

%# To be diagonally dominant, the row and column sums have to be less
%# than twice the diagonal
rowSum = sum(absArray,1)';%#' (formatting comment)
colSum = sum(absArray,2);
dia    = diag(absArray);

%# test
isDiagonallyDominantByRow = all(rowSum <= 2 * dia); 
isDiagonallyDominantByCol = all(colSum <= 2 * dia);
isTotallyDominant = isDiagonallyDominantByRow && isDiagonallyDominantByCol;
Jonas
Following wiki's definition you shouldn't test both rowSum and colSum in the same test. The answers can be isDiagonallyDominantByRows or isDiagonallyDominantByColumns.
yuk
@yuk: Thanks, fixed it.
Jonas

related questions