While loop not stopping

1 view (last 30 days)
Shan e Zehra Lashari
Shan e Zehra Lashari on 15 Feb 2017
Answered: Roger Stafford on 15 Feb 2017
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 Comment
KSSV
KSSV on 15 Feb 2017
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.

Sign in to comment.

Answers (1)

Roger Stafford
Roger Stafford on 15 Feb 2017
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.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!