Salman Saeed
Salman Saeed

Reputation: 13

How to stop iteration when the output does not change in Matlab?

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. What approach should I take? 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?

Upvotes: 0

Views: 129

Answers (2)

user1543042
user1543042

Reputation: 3440

if abs(old - new) < threshold
    break
end

Upvotes: 1

Mirza Awais Ahmad
Mirza Awais Ahmad

Reputation: 133

The simplest approach can be to check the change in probability in every iteration by subtracting the new probability from the previous one and exiting the loop once this change goes below a threshold.

Upvotes: 0

Related Questions