16.6k views
2 votes
Basically, if for every row, the absolute value of the entry along the main diagonal is larger than the sum of the absolute values of all other entries on that row. Write a function whose input is a matrix and will determine (true/false) if a matrix is diagonally dominant. Show that your function works as expected.

User Mahesh K S
by
4.7k points

1 Answer

0 votes

Answer:

Check the explanation

Step-by-step explanation:

MATLAB code:

%----------------------

function result = dominant(A)

% matrix dimensions

d = size(A);

% for loop over rows

for i = 1:d

% sum of row elements except diagonal element

sum_row =0;

% for loop over columns

for j = 1:d

% adding each elements to sum variable

sum_row = sum_row+ abs(A(i,j));

end

%subratcting diagonal element

sum_row = sum_row-abs(A(i,i));

%checking dominant condition

% failed once means matrix is not diagonal dominant

if abs(A(i,i))< sum_row

result = 'false';

return;

end

end

% dominant condition not failed

result = 'true';

end

% matrix A

A = [ 3 -2 1; 1 -3 2; 1 2 6]

% result

result = dominant(A)

% matrix A

A = [ -2 1 2; 1 3 2; 1 -2 0]

% result

result = dominant(A)

%----------------------

Kindly check the attached output image below.

Basically, if for every row, the absolute value of the entry along the main diagonal-example-1
User Pi
by
5.1k points