MATLAB: How to stop when same result the program

same resulstopping criteria for optimization

I need stoping same resul my program. if my program starts to give the same results, it should stop. Pls help me.

Best Answer

Keep a variable which is the previous result. If the absolute value of the difference between the new result and the previous result is small enough, then break the loop.