Path: news.mathworks.com!not-for-mail
From: "Steve " <steveDEL.bachmeierDEL@yahoo.com>
Newsgroups: comp.soft-sys.matlab
Subject: while loop problem
Date: Fri, 7 Mar 2008 23:49:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 40
Message-ID: <fqsk9e$73s$1@fred.mathworks.com>
Reply-To: "Steve " <steveDEL.bachmeierDEL@yahoo.com>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1204933742 7292 172.30.248.38 (7 Mar 2008 23:49:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 7 Mar 2008 23:49:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1034320
Xref: news.mathworks.com comp.soft-sys.matlab:456058



I'm trying to grow a vector using 'while' and there seems 
to be a sort of instability somewhere.  Sometimes (but not 
always), it does not stop looping when I think it should.  
I have copied part of the code below.

On several equations, plotting Kmax_net shows that Kmax_net 
does become larger than Kc.  There is always an immediate 
drop off at this point, and Kmax_net starts growing again.  
This may happen two or three times before it finally goes 
above Kc and the loop ends.  Why isn't the loop terminating 
the first time through?  Any suggestions?  Thanks!

----------------------

while Kmax_net(i)<Kc
    i=i+1;
    % calculate crack propagation
    Kmax_app(i)=1.12*Smax*sqrt(pi*a(i-1));
    Kmin_app(i)=1.12*Smin*sqrt(pi*a(i-1));
    Kresidual(i)=interp1(KresTable(:,1),KresTable(:,2),a(i-
1));
    Kmax_net(i)=Kmax_app(i)+Kresidual(i);
    if Kmax_net(i)<0
        Kmax_net(i)=0;
    else
        Kmax_net(i)=Kmax_net(i);
    end
    Kmin_net(i)=Kmin_app(i)+Kresidual(i);
    if Kmin_net(i)<0
        Kmin_net(i)=0;
    else
        Kmin_net(i)=Kmin_net(i);
    end
    dKnet(i)=Kmax_net(i)-Kmin_net(i);
    Rnet(i)=Kmin_net(i)/Kmax_net(i);
    da(i)=C*(dKnet(i))^M/((1-Rnet(i))*Kc-dKnet(i));
    a(i)=a(i-1)+da(i);
end

------------------------------