% Is a matrix diagonally dominant? % CONVERT THIS TO A FUNCTION exactly ASKED FOR in the problem statement clc A=[7.1 3 4; 4 -10 6; 12 12 24] % size of matrix n=length(A) % countg used as a counter as for how many rows the inequality is met % strictly, that is only greater than is allowed countg=0 % countg used as a counter as for how many rows the inequality is NOT met % strictly, that is greater than equal to is allowed countge=0 for i=1:1:n % finding the right hand side of the inequality sum=0 for j=1:1:n if i~=j sum=sum+abs(A(i,j)) end end % Comparing the LHS and RHS of strict inequality if abs(A(i,i))>sum countg=countg+1 end % Comparing the LHS and RHS of not strict inequality if abs(A(i,i))>=sum countge=countge+1 end end % If the strict inequality is satisfied for at least one row and the inequality for all the rows, % then the matrix is diagonally dominant, else it is not diagonally dominant. if countg>=1 & countge==n fprintf('Diagonally dominant') else fprintf('Not diagonally dominant') end