Write a function file that takes as input a matrix A, and tests whether or not the matrix is (a) square, and (b) diagonally dominant, reporting the answers on the screen. Show that your code is correct by testing it for the matrix in question 2, as w

3 views (last 30 days)
Write a function file that takes as input a matrix A, and tests whether or not the matrix is (a) square, and (b) diagonally dominant, reporting the answers on the screen. Show that your code is correct by testing it for the matrix in question 2, as well as for cases where the matrix is not diagonally dominant, and not square.
  3 Comments
Image Analyst
Image Analyst on 12 Apr 2020
Kasigo: Try this:
m = zeros(3, 3, 3, 3);
if length(unique(size(m))) == 1 % Works for any number of dimensions of matrix (2-D, 3-D, 4-D, etc.)
fprintf('Array is square.\n');
else
fprintf('Array is NOT square.\n');
end
Surely a smart guy like you can take the definition from Wikipedia: Diagonally_dominant_matrix and do the code.

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 15 Mar 2015
Functions that may help you: size(), warndlg(), sprintf(), inputdlg(), fprintf(), helpdlg().
Hints:
message = sprintf('The value is %f', theValue);
uiwait(helpdlg(message));
errorMessage = sprintf('This array is not square!\nIt has %d rows and %d columns', rows, columns);
uiwait(warndlg(errorMessage));
fprintf('%s\n', errorMessage);

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!