필터 지우기
필터 지우기

want to follow my iteration - how?

조회 수: 3 (최근 30일)
Meh
Meh 2011년 10월 7일
Hi, I want to follow how my while-loop iteration is proceeding at each step. How can I do this?****I want to understand and correct why my iteration is never ending:
v_m=10;
R_try=0;
v_m_try=0;
while abs(v_m_try-v_m)>0.01
if (v_m_try<v_m)
R_try=R_try+0.05;
v_0_try=sqrt(9.81*R_try*0.02);
v_m_try=0.4*log(12.27*v_0_try^2);
else
R_try=R_try-0.05;
v_0_try=sqrt(9.81*R_try*0.02);
v_m_try=0.4*log(12.27*v_0_try^2);
end
end
  댓글 수: 2
Jan
Jan 2011년 10월 7일
Please use proper code formatting. Follow the "Markup help" link on this page.
Florin Neacsu
Florin Neacsu 2011년 10월 7일
Maybe use debugger?

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

채택된 답변

Andrei Bobrov
Andrei Bobrov 2011년 10월 7일
v_m=10;
R_try=0;
v_m_try=0;
i1 = 0;
while abs(v_m_try-v_m)>0.01 && i1 < 100
if v_m_try<v_m
R_try=R_try+0.05;
else
R_try=R_try-0.05;
end
v_0_try=sqrt(9.81*R_try*0.02);
v_m_try=0.4*log(12.27*v_0_try^2);
i1 = i1 + 1;
out(i1,:) = [R_try, v_m_try];
end
  댓글 수: 6
Matt Tearle
Matt Tearle 2011년 10월 7일
FWIW, rather than fzero, you could also just do it algebraically: R_try = exp(10/0.4)/(12.27*9.81*0.02)
Andrei Bobrov
Andrei Bobrov 2011년 10월 7일
Thanks Matt! I've been seeing only the "fzero", "fsolve" b and other tricks - I'm a hostage MATLAB, I start to forget algebra - my fault ... :)

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

추가 답변 (1개)

Bjorn Gustavsson
Bjorn Gustavsson 2011년 10월 7일
If you want to see what's going on you can use:
disp([v_m,v_m_try,v_0_try,R_try])
If that is not detailed enough check the trusty pair: fprintf and sprintf.
HTH,

카테고리

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