Regular matrix and non-singular matrix

Hey
I need to write a function that the user enters a matrix, and the function returns "1" if the matrix is reversible(regular) and "0" if it's not.
I wrote this function-
function x=irr_mat(A)
if isequal(A,zeros(n))
x=0;
else
if size(A,1)==size(A,2)
x=1;
else
x=0;
end
end
end
n is the array of the matrix.
and I got this note-
Error in irr_mat (line 3)
if isequal(A,zeros(n))
Error in Untitled5 (line 3)
irr_mat(A)
any help?

14 件のコメント

Stephen23
Stephen23 2020 年 10 月 20 日
Where do you define n ?
Noa  Yelin
Noa Yelin 2020 年 10 月 20 日
I just find out that I didn't define n.
How can i define n that the user can put in matrix in which size he want to?
Noa  Yelin
Noa Yelin 2020 年 10 月 20 日
any help?
How can i define n that the user can put in matrix in which size he want to?
Steven Lord
Steven Lord 2020 年 10 月 20 日
You compute it from the input the user gave you using size.
Noa  Yelin
Noa Yelin 2020 年 10 月 20 日
n=size?
Noa  Yelin
Noa Yelin 2020 年 10 月 20 日
function x=irr_mat(A)
n=size
if isequal(A,zeros(n))
x=0;
else
if size(A,1)==size(A,2)
x=1;
else
x=0;
end
end
end
it print me -
Error in irr_mat (line 3)
n=size
Error in Untitled5 (line 3)
irr_mat(A)
Steven Lord
Steven Lord 2020 年 10 月 20 日
size requires at least one input, the array whose size you're trying to compute. In this case you probably want to call it with two inputs. To see what that second input represents, I recommend reading or at least skimming the documentation page.
doc size
Noa  Yelin
Noa Yelin 2020 年 10 月 20 日
ok when i did this functionn -
function x=irr_mat(A)
n=size(A)
if isequal(A,zeros(n))
x=0;
else
if size(A,1)==size(A,2)
x=1;
else
x=0;
end
end
end
and call the function -
A=randi([0,100],4);
irr_mat(A)
I don't get matrix.. i get always -
n =
4 4
ans =
1
Francesco Tricarico
Francesco Tricarico 2020 年 10 月 20 日
You've said
"I need to write a function that the user enters a matrix, and the function returns "1" if the matrix is reversible(regular) and "0" if it's not."
It seems that you're last function version works well ("1" is the expected output).
Noa  Yelin
Noa Yelin 2020 年 10 月 20 日
yes, but when i wrote 4 here -
A=randi([0,100],4);
irr_mat(A)
i need to get matrix with 4X4.
Rik
Rik 2020 年 10 月 20 日
A is 4x4, x is not.
KSSV
KSSV 2020 年 10 月 20 日
You asked the same question three times. There is no clarity in your question.
Noa  Yelin
Noa Yelin 2020 年 10 月 20 日
i dont get A 4X4. I got -
n =
4 4
ans =
1
I need to get matrix A with 4 rows and 4 columns
Steven Lord
Steven Lord 2020 年 10 月 20 日
What specifically do you mean by "reversible(regular)"? Which of the following count as reversible / regular and why do they count or not count?
A1 = 1
A2 = 42
A3 = 99
A4 = 12321
A5 = [1 2; 3 4]
A6 = [1 23; 23 1]
A7 = [98 89; 764 467]
A8 = [1 2 3 4; 5 6 7 8; 9 10 10 9; 8 7 6 5; 4 3 2 1]

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLinear Algebra についてさらに検索

製品

質問済み:

2020 年 10 月 20 日

コメント済み:

2020 年 10 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by