please explain the working of 2nd ,3rd and 4th statements of this coding portion:
1 view (last 30 days)
John Chilleri on 15 Feb 2017
This code checks to see if the diagonal elements of a given matrix A (assuming n x n) are larger in magnitude than the sum of the magnitude of the non-diagonal elements in its row.
Line by line explanation:
The first line loops through all the rows of A.
for i = 1:n
The second line is defining j = [1 2 3 ... n], so a vector containing 1..n,
j = 1:n;
The third line is removing the diagonal element, aka, the ith row and this removes the ith column, so the i,i th element,
j(i) = ;
The fourth line takes the absolute value of all the elements in the ith row of A, excluding the diagonal element: A(i,j) = A(ith row, elements 1,2,...,i-1,i+1,...,n) since we removed the ith element from j previously.
B = abs(A(i,j));
The fifth line computes the absolute value of the diagonal element minus the sum of the absolute value of all the other elements in the row. If Check is positive, we know the magnitude of the diagonal element was greater than the sum of all the magnitudes of the other elements in its row.
Check(i) = abs(A(i,i)) - sum(B);
The sixth line checks if it's less than zero, in which case the diagonal elements magnitude is not greater than or equal to the sum of the magnitudes of the other elements.
if Check(i) < 0
If this is the case, the matrix is not strictly diagonally dominant, which the seventh line prints.
fprintf('The matrix is not strictly diagonally dominant at row %2i\n\n',i)
The eighth and ninth lines end the cycle.
Sorry if this was too much detail,
Hope this helps!