Can someone help me with my if statements in my function?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I have written this function for a homework assignment, Basically finding heronian isosceles triangles for a given Perimeter. My if statements
if ((b>= 2*a)) && ((b<=0));
continue
end
if IntTestA == 0
a=0; b=0; A=0;
continue
end
are not working properly I was wondering if someone could explain to me why.
1 Kommentar
Jan
am 1 Mai 2016
Bearbeitet: Jan
am 1 Mai 2016
This is not twitter - tags do not need hash characters.
Before we can explain, why the code is not working "properly", we have to know, what you call "poperly". Note that all information we have is the "failing" code. And this code does exactly what its lines commands it to do. Due to the absence of comments, guessing your intention is risky.
Akzeptierte Antwort
Jos (10584)
am 1 Mai 2016
I quickly see three issues:
- a is always positive so b can never be both positive (>=2*a) and negative (<= 0).
- for A = sqrt(...) is a loop over a single value
- setting the iterator in a loop (a=0) does not effect the loop. See this example
for k=1:5
disp(k)
k = 5 ;
disp(k)
end
Weitere Antworten (1)
Roger Stafford
am 1 Mai 2016
Your test “IntTestP==0” does not accomplish what you think it does. The only way “fix((fix(P)-P)+1)” can be zero is for P to be a positive non-integer, and the further requirement that P<=0 is then impossible which means that the error message can never be issued.
1 Kommentar
Siehe auch
Kategorien
Mehr zu Testing Frameworks finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!