While loop not stopping

조회 수: 1 (최근 30일)
Shan e Zehra Lashari
Shan e Zehra Lashari 2017년 2월 15일
답변: Roger Stafford 2017년 2월 15일
Hi
I am new to matlab. Help appreciated. I have run below code and it is not stopping. though its working well.
CL=9.0e-6;
h=50.0;
E=6.0e10;
u=0.2;
q=1.0e-2;
tp=12000;
Sp=0;
v=0.25;
wmax=1;
wavg=pi/4*wmax;
L=((q*tp)/((wavg*h)+(CL*h*(tp^0.5))+(Sp*h)));
wmax1=3*(((q*u*L)/E)^0.25);
D= abs(wmax1-wmax);
while D>=0.000001
wavg=wmax1;
L1=((q*tp)/((wavg*h)+(CL*h*(tp^0.5))+(Sp*h)));
wmax1=3*((q*u*L1)/E)^0.25
end
disp (L1)
  댓글 수: 1
KSSV
KSSV 2017년 2월 15일
Your wmax1 always remain same.....why you need a loop if it is the case? D should be calculated at every step inside loop, so that D condition can be met and loop exits. You have to rethink on L1 and wmax1 calculation so that loop can influence it.

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

답변 (1개)

Roger Stafford
Roger Stafford 2017년 2월 15일
In addition to KSSV’s correction, there is another fundamental difficulty with your procedure. In effect you are attempting to solve the following equation for the unknown x
x = 3*((q*u*((q*tp)/((wavg*h)+(CL*h*(tp^0.5))+(Sp*h))))/E)^0.25
by repeatedly replacing x by the expression on the right hand side. Given the value of the various constants, your procedure does in fact converge, though it requires some twenty-five steps before the full sixteen decimal-place accuracy of matlab can be achieved, which is very slow convergence. However, this convergence rate depends very heavily on the particular values of the various constants involved and could well diverge instead of converging. What you need is an algorithm such as the Bisection or the Newton-Raphson methods which assure of you proper convergence. Using your iteration technique is a little like tossing a coin several times and hoping each toss will be heads.

카테고리

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