I am posting this question because, my code is not stopping iteration at the right place. Could anyone make me sure what is wrong?

Everything is working properly (as I always think which is mistake in reality..)

**Question:** 

**1)** In each iteration, I am minimizing Unfortunately, it is not minimizing correctly (very poor result). Am I stopping iteration correctly in minimization process? Any suggestions?

**Just run the following code:**

```
import numpy as np
from scipy.stats import stats
def run_iter():
    # Initial guess
    x_new = x0
    # just to pretend we have huge error
    phi0 = 1e20
    for i in range(iter_num):
         # first solution
         x_next = x_new

         # FIRST WAY
         # First assumption to stop the iteration...

         # SECOND WAY
         '''
         # Second assumption to stop the iteration
         '''
    return x_new

def example_run():

if __name__ == '__main__':
    print example_run()

```