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 次查看(过去 30 天)
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 个评论
Image Analyst
Image Analyst 2020-4-12
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.

请先登录,再进行评论。

回答(1 个)

Image Analyst
Image Analyst 2015-3-15
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);

类别

Help CenterFile Exchange 中查找有关 Operating on Diagonal Matrices 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by