# Check Diagonal dominance Row Wise & Column Wise using MATLAB

Diagonal Dominance Row Wise

If a Matrix is diagonal dominant row wise, the absolute value of the diagonal element in that matrix must me greater than or equal to the sum of absolute value of other elements in that row of the matrix.

In MATLAB terms, abs(diag(A)) must be greater than sum(abs(A),2)-abs(diag(A)). The abs(diag(A)) is subtracted from sum(abs(A),2) since the command also include the diagonal element in the sum done row wise.
Thus the net formula to check the row dominance row wise can be seen as abs(diag(A))-(sum(abs(A),2)-abs(diag(A)))==2*abs(diag(A))-sum(abs(A),2) which must result greater than zero in order to have a dominance. The condition has to be true for all the rows of the matrix.

Thus the MATLAB command which will help to find dominance will be;

x=all((2*abs(diag(A)))- sum(abs(A),2)>=0); %sum(abs(A),2) will perform addition row wise
if x==0
disp('Matrix is not Diagonal Dominant Row wise')
else
disp('Matrix is Diagonal Dominant Row wise')
end

Where A is a square matrix. Variable x stores the logical value of either 1 or 0 depending on the Matrix A specified by the user.
x will have a value of 0 if the matrix A is not diagonal dominant row wise.
x will have a value of 1 if the matrix A is diagonal dominant row wise.

Sample Input & Output:
(1) if

A =[1     2     3
4     5     6
7     8     9]

x =     0

Matrix is not Diagonal Dominant Row wise

(2)
if
B =[4     1     1
4     9     2
2     3     8]
x =    1
Matrix is Diagonal Dominant Row wise

Diagonal Dominance Column Wise

In this case all the other conditions are same, only sum(abs(A),2)  is changed to sum(abs(A)) or sum(abs(A),1) (Here 1 is the default argument of the  function if the value is not specified)

The the MATLAB program to Check for the Diagonal Dominance Column Wise:

x=all((2*abs(diag(A)))- sum(abs(A))>=0);
%sum(abs(A)) will perform addition column wise
if x==0
disp('Matrix is not Diagonal Dominant Column wise')
else
disp('Matrix is Diagonal Dominant Column wise')
end

Where A is a square matrix. Variable x stores the logical value of either 1 or 0 depending on the Matrix A specified by the user.
x will have a value of 0 if the matrix A is not diagonal dominant column wise.
x will have a value of 1 if the matrix A is diagonal dominant column wise.

NOTE : One more variant of the code for Diagonal Dominance Column Wise could be that in the initial step we take a transpose of the matrix A. Then using the transposed value in the subsequent steps.

Sample Input & Output:
(1) if

A =[1     2     3
4     5     6
7     8     9]

x =     0

Matrix is not Diagonal Dominant Column wise

(2)
if
B =[8     1     1
4     9     2
2     3     8]
x =    1
Matrix is Diagonal Dominant Column wise

Further Variation of this program  may include functions or options to check for Diagonal Dominance column & row wise simultaneously.

Update 03/09/2014
To check for the condition of strict diagonal dominance. The condition would be that instead of ">=" sign we should be using only ">" sign.
i.e.,
To check for the matrix to be strictly diagonal dominant row wise the MATLAB code snippet will become as,

x=all((2*abs(diag(A)))- sum(abs(A),2)>0); %sum(abs(A),2) will perform addition row wise
if x==0
disp('Matrix is not Diagonal Dominant Row wise')
else
disp('Matrix is Diagonal Dominant Row wise')
end

Same thing for matrix to be strictly diagonal dominant column wise the MATLAB code snippet will be,

x=all((2*abs(diag(A)))- sum(abs(A))>0); %sum(abs(A)) will perform addition row wise
if x==0
disp('Matrix is not Diagonal Dominant Row wise')
else
disp('Matrix is Diagonal Dominant Row wise')
end