the value of y in the while loop doesn't vary from the previous ?
조회 수: 1 (최근 30일)
이전 댓글 표시
>> n=2;
>>t=520
>> r=5;
>> p=1000;
>> x=n*r*t/p;
a=1; , b=2;
>> y=n*r*t/(p+a*n^2/x^2))+n*b;
while abs(x-y)<= 0.001
x=y;
y=n*r*t/((p+a*n^2/x^2))+n*b;
end
댓글 수: 0
채택된 답변
Walter Roberson
2013년 2월 26일
I suspect you will find that your while loop body is not executing at all.
댓글 수: 7
Image Analyst
2013년 2월 28일
It's not even satisfied the very first time! Like Walter tried to tell you, the first time it hits that line, x = 5.2, and y = 9.1992, so abs(x-y) = 3.992 and since this is not less than 0.001, your loop never even gets entered the very first time. If you learn how to use the debugger, or simply leave off semicolons, you will discover these kinds of things very very easily and quickly.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!