2
$\begingroup$

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

Thanks, Vojta

$\endgroup$
1
$\begingroup$

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
$\endgroup$
  • $\begingroup$ Of course, this calls eig, which you may not want to do. In that case you might have to code for other sufficient conditions. $\endgroup$ – Emily Aug 23 '13 at 19:21
  • $\begingroup$ if (any(eig(A) <= 0)) was intended, right? And similarly for the second test. $\endgroup$ – user66081 Apr 21 '17 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.