Error with the while nested in a for loop

1 回表示 (過去 30 日間)
Shashanka
Shashanka 2014 年 7 月 14 日
コメント済み: Star Strider 2014 年 7 月 14 日
Hi, I am encountering some issues with the while nested within a for loop. The result goes into an infinite loop in this case and sometimes no messages are displayed. For every value of the TSR (1:10), I need to get the AxIFN and AnIFN once the while loop is exited. The value of TSR is incremented by 1 (1:10). Please find the code attached the code below. Thanks in advance.
  2 件のコメント
Sara
Sara 2014 年 7 月 14 日
It just means that the condition of the while loop is never satisfied. After 10,000 loops, AxIF = 6e-3 for instance. you'll have to recheck your equations or post which kind of algorithm you are trying to implement.
dpb
dpb 2014 年 7 月 14 日
...result goes into an infinite loop in this case and sometimes no messages are displayed...
b) Looks to me like you've commented out any messages so that's not terribly surprising.
a) Take one of these cases that causes the problem and set a breakpoint when start the loop and step thru to see where the logic breaks down or output intermediary results to a file for inspection. If the while never exits, that's owing to the computed value of the control variable never reaching that criterion. So, you need to ascertain whether that's an error in the computation or the range of inputs is such that the output can't happen (probably most likely I'd guess, just looking at the code).
The way this is prevented in most production code is by having an iteration loop counter that has some upper limit at which it determines it's give-up time and aborts.

サインインしてコメントする。

採用された回答

Star Strider
Star Strider 2014 年 7 月 14 日
編集済み: Star Strider 2014 年 7 月 14 日
Change these two lines to include subscripts:
AxIFN(TSR) = (1 + (N/D)).^-1; % Axial Induction Factor---- a
AnIFN(TSR) = ((S.* Cl)/(4.*TSR.* cos(phiradN))) * (1 - AxIF); % Angular Induction Factor---- a'
and
AxIF = AxIFN(TSR);
AnIF = AnIFN(TSR);
So long as TSR is a positive integer, you will have no problems, and AxIFN and AnIFN will each be a (1x10) vector.
  2 件のコメント
Shashanka
Shashanka 2014 年 7 月 14 日
Could you please tell me what subscript should I be adding? This is the first time I am ever using MATLAB. The for and the while loops when run individually I do not encounter any such issues!
Star Strider
Star Strider 2014 年 7 月 14 日
Use TSR as your subscript variable, since it is your loop index.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by