I keep getting the error "Index in position 2 exceeds array bounds (must not exceed 8) with the following code. I am trying to determine whether a matrix is strictly diagonally dominant or not. The error appears on the line with sumrow=sumrow+abs(A(i,j));
This is the code.
A = [28 -6 4 1 -2 -5 8 0; -4 28 -1 4 0 4 4 6; 1 -6 26 -5 1 -1 -6 0; 1 -6 26 -5 1 -1 -6 0; -5 -6 1 21 0 -3 2 2; 4 1 3 -3 17 0 -3 3; 4 -2 3 0 2 14 0 1; 1 2 4 3 -2 1 17 4; 1 3 1 3 0 -1 3 15];rowcol=size(A);n=rowcol(1); count=0;for i=1:1:n sumrow=0; for j=1:1:n if i~=j sumrow=sumrow+abs(A(i,j)); end end if abs(A(i,i))>sumrow count=count+1; endendif count==n disp('Matrix is strictly diagonal dominant')else disp('Matrix is NOT strictly diagonal dominant')end
Any help with corrections will be greatly appreciated.
Best Answer