How to make while loop faster ?
1 回表示 (過去 30 日間)
古いコメントを表示
Hello all ,
I have so simple while loop to sum , and it is taking really so long time , and i do not know if it is normal to take this time or not
D_1 = 1.5e-13;
D = 0;
n = 0;
n_cyc = [0.500000000000000 15.5000000000000 1 1 1 1 1 1 1 1 1 1 1 0.500000000000000 0.500000000000000];
while D < 1
% D factor
D = D +D_1; % total damage
n= n + sum(n_cyc); % sum of cyclic Values for all the Blocks till the Fracture
end
Thank you for any helping
0 件のコメント
回答 (1 件)
Star Strider
2020 年 9 月 18 日
First, the number of iterations is going to be:
n_iter = 1/D_1
evaluating to:
n_iter =
6.666666666666667e+12
That is going to take a while.
I do not understand the reason for the loop anyway.
Unless I am missing something, at the end of the loop:
n = sum(n_cyc) * n_iter
or:
n =
1.866666666666667e+14
So I would simply do that one multiplication and be done with it!
2 件のコメント
Star Strider
2020 年 9 月 18 日
My pleasure!
I would not use such a small step (1.5e-13) initially. Use larger steps, determine when the failure occurs, then use those limits in subsequent runs of the while loop with progressively smaller steps over a smaller total interval to determine more precisely when the failure occurs.
It still might be more efficient to use other approaches than a while loop, however since I have no idea what you are doing, I have no idea what to suggest.
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!