Writing a code to attempt to make matrix diagonally dominant

6 views (last 30 days)
I have a code that will perform the Gauss-Seidel method, but since one of the requirements for the matrix of coefficients is that it be diagonally dominant, I am trying to write a function that will attempt to make the matrix diagonally dominant--preserving each row, just trying to swap around rows until the condition is met. I'm not really sure where to start with this. My first thought was to rearrange the matrix so the maximum in each row was in the diagonal position:
for i = 1:n
maxx = max(dummy(i,:));
[rn, p] = find(dummy(i,:) == maxx);
a(p,:) = dummy(i,:);
end
However, this runs into issues when you have a matrix like [3 -4 12; 6 7 -1; 2 9 1] which is diagonally dominant arranged like [6 7 -1; 2 9 1; 3 -4 12] as it will end up with two identical lines. What I'd like to do is come up with a loop of some sort to first test to see if the matrix is diagonally dominant, and then switch rows, test for diagonal dominance again, and repeat until either the matrix meets the criteria, or until it has tried every possible row combination at which point it could print 'matrix cannot be made diagonally dominant'. Is this possible and if so, where should I start? Thank you.

Answers (1)

edgar gonzalez
edgar gonzalez on 18 Dec 2017
I figured out how to to make (if it's possible) a matrix diagonally dominant using the command perms which gives a matrix of permutations, selecting each each row, you get a way to arrange your elements by rows or columns, and then check if that array gives you a diagonally dominant matrix

Categories

Find more on Operating on Diagonal Matrices in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!