How to stop an Iteration when the output converges (stops changing)

2 ビュー (過去 30 日間)
Salman Saeed
Salman Saeed 2015 年 7 月 14 日
回答済み: Rizwan Khan 2020 年 9 月 8 日
I have 2048 master equations, dp/dt = Tj - Ti(p) for 2048 states of a network where p is the probability at a specific time. Initial p of all the states is 1/2048. All the Tj and Ti values are given for all the equations. I need to solve all these master equations using the iterative method until the probability of each state does not change. I am applying simple iteration using the for loop. What will be the code of the condition to stop the loop of each of the equation differently when their respective values are not changing?

回答 (2 件)

Luis Gomes Perini
Luis Gomes Perini 2015 年 7 月 14 日
Hi,
let's suppose that at iteration 'n' you have a probability 'p'. Then, for example, you can stop your loop when abs(p_n - p_{n-1}) < C , 'C' being a chosen value as 10^{-3}.
Sure, there exists many other stop criteria that might be more or less adapted for your problem.

Rizwan Khan
Rizwan Khan 2020 年 9 月 8 日
% break command can be used for this purpose
for i = 1:inf
...you code
if abs(p(i+1)-p(i)) < s % where s is very small value
break
else
return
end
end

カテゴリ

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