Effacer les filtres
Effacer les filtres

How do I construct this function?

1 vue (au cours des 30 derniers jours)
Riyaz Bhayat
Riyaz Bhayat le 16 Jan 2020
Commenté : Steven Lord le 16 Jan 2020
I am in need of some help regarding this question,
Write a function Matrix Count(matrix) that has as input a matrix and has as output a string If the matrix is not square, the output string is 'this is not a square matrix'. If the matrix is square, the output string is 'this matrix has determinant ??'
Any guidance would be very much appreciated
Thanks
  2 commentaires
Spencer Chen
Spencer Chen le 16 Jan 2020
Do you know how to check the size of a matrix?
Steven Lord
Steven Lord le 16 Jan 2020
This sounds like a homework assignment. If it is, show us the code you've written to try to solve the problem and ask a specific question about where you're having difficulty and we may be able to provide some guidance.
If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the MATLAB Onramp tutorial (https://www.mathworks.com/support/learn-with-matlab-tutorials.html) to quickly learn the essentials of MATLAB.

Connectez-vous pour commenter.

Réponse acceptée

Allen
Allen le 16 Jan 2020
The following should accomplish what you are asking.
function TF = issquare(A)
% Verifies that A is a numerical matrix with more that one element (ie - scalar).
if isnumeric(A) && ismatrix(A) && numel(A)>1
% Get the size (rows & columns) of A
sz = size(A); % sz(1)==# of rows and sz(2)==# of columns
if isequal(sz(1),sz(2))
TF = 'this matrix has determinant';
% Would recommend making TF a boolean instead of a message (ie - true/false)
% TF = true;
else
TF = 'this is not a square matrix'
% Would recommend making TF a boolean instead of a message (ie - true/false)
% TF = false;
end
else % Input is either a scalar value, non-numeric, and/or is not a matrix.
error('Invalid Input: Must be a numerical, non-scalar, matrix.')
end
end

Plus de réponses (0)

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by