Info

This question is closed. Reopen it to edit or answer.

Problem with if and than and det

4 views (last 30 days)
bondpen
bondpen on 12 Apr 2018
Closed: bondpen on 13 Apr 2018
So basically im trying script that determines if matrix is singular or not, by doing a det on the matrix. For example i tired doing: det([1 2;3 4]) which result in zero, but when I tired to input into the command like singularitytest([1 2;3 4]) or A=[1 2;3 4] its output is just the matrix. I am not sure which part i have gotten wrong, the If and else statements or the det? or my input command?
function result = singularitytest(A)
if det(A) == 0
c = 0;
else
c = 100;
end
  2 Comments
Stephen23
Stephen23 on 12 Apr 2018
Edited: Stephen23 on 12 Apr 2018
bondpen
bondpen on 13 Apr 2018
Thanks! Both this and my result/variables mix up helps me.

Accepted Answer

Walter Roberson
Walter Roberson on 12 Apr 2018
You assign something to variable named c, which you then do not use.
Your function expects something to be assigned to result but you never assign to that.
  1 Comment
bondpen
bondpen on 13 Apr 2018
Thanks! Both this and cond command helps me.

More Answers (0)

This question is closed.

Community Treasure Hunt

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

Start Hunting!