2

Is there a simple way to check that matrix is M-matrix in Octave/Matlab?

Thanks, Vojta

1 Answers1

1

Let's see if this works:

% A is our matrix
[n,m] = size(A);
if (any(eig(A)) <= 0)
    % Then A is not an M-matrix
    break;
else
    idx = find(A > 0);
    [I,J] = ind2sub([n,m],idx);
    % I and J are the row/col subscript indices for positive entries.
    % We should only have this when i = j. If i =/= j, then i-j =/= 0,
    % so we look for non-zero entries in I-J
    if (any(I-J) ~= 0)
        % Then A is not an M-matrix
        break;
    else
        disp 'M-matrix!';
    end
end
Emily
  • 36,334
  • Of course, this calls eig, which you may not want to do. In that case you might have to code for other sufficient conditions. – Emily Aug 23 '13 at 19:21
  • if (any(eig(A) <= 0)) was intended, right? And similarly for the second test. – user66081 Apr 21 '17 at 15:45