I got error as stated below, your assistance would be greatly appreciated, Thank you
A=3e3;
B=2e3;
while (abs(A-B))<50
x=4*A;
y=B*A*3;
end
x
y
****** Undefined function or variable 'x'.
Error in ddff (line 7) x
********

 채택된 답변

Mischa Kim
Mischa Kim 2014년 2월 9일
편집: Mischa Kim 2014년 2월 9일

0 개 추천

UTS, with those values for A and B you never enter the loop and therefore no values are assigned to x, which is why it is not defined.
One thing you could do is initialize x and y to zero before the loop.

댓글 수: 2

Thank you very much, I did the initial values of x & y to zero, but the answer also zero, A=3e3;
B=2e3;
x=0;
y=0;
while (abs(A-B))<50
x=4*A;
y=B*A*3;
end
x
y
*************
x =
0
y =
0
Mischa Kim
Mischa Kim 2014년 2월 9일
Right, as I pointed out above, with A = 3000 and B = 2000 you never enter the loop, since 3000 - 2000 > 50. Try for example A = B = 3000. Note, however, that you are neither changing A nor B inside the loop. This means that the loop condition is always satisfied and you're stuck in an endless loop.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

질문:

UTS
2014년 2월 9일

댓글:

2014년 2월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by