A very simple while loop

조회 수: 3 (최근 30일)
Truman Cassady
Truman Cassady 2018년 4월 14일
댓글: Truman Cassady 2018년 4월 14일
while tol<10E-6
E= M+e*sin(E)
n=n+1;
E = M + (M+e*sin(E))
tol(:,1)= E(n+1)-E(n)
end
If I don't assign an index to the E value in this loop how can I reference two values in the sequence. Everything works, but I just need clarification on the index values for the tol variable.

답변 (1개)

Walter Roberson
Walter Roberson 2018년 4월 14일
while tol<10E-6
means the same thing as
while all(tol(:)<10E-6)
When you make tol a vector then all of the entries have to be true in order to proceed.
If you do not need a record of the tol values, then just assign tol = E(n+1)-E(n) ;
If you do need a record of the tol values, then use while tol(end)<10E-6
... Or probably, while abs(tol(end))>10E-6 since you probably want to stop when the you get close enough.
  댓글 수: 1
Truman Cassady
Truman Cassady 2018년 4월 14일
I posted an updated screen capture of my code. Thank you for responding to me on a Saturday btw. I can't correctly build a new tolerance value with each successive iteration.

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

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by