title: Lack of convergence in scipy-optimize-minimize minimization
body: <p>Overall, I am trying to "scale" an array such that the integral of the array is 1, i.e. the sum of array elements divided by the number of elements is 1. This scaling, however, must take place by changing the parameter alpha and not by simply multiplying the array by a scaling factor. To do this, I am using scipy-optimize-minimize. The problem is that the code runs, with the output "Optimization terminated successfully", but the current function value displayed is not 0, so clearly the optimization was not actually successful.</p>
  
  <p><a href="https://i.stack.imgur.com/cYd4m.png" rel="nofollow noreferrer">This is a screenshot from the paper that defines the equation.</a></p>
  
  <pre><code>import numpy as np
  from scipy.optimize import minimize
  
  # just defining some parameters
  N = 100
  g = np.ones(N)
  eta = np.array([i/100 for i in range(N)])
  g_at_one = 0.01   
  
  def my_minimization_func(alpha):
      g[:] = alpha*(1+(1-g_at_one/alpha)*np.exp((eta[:]-eta[N-1])/2)*(1/np.sqrt(3)*np.sin(np.sqrt(3)/2*(eta[:] - eta[N-1])) - np.cos(np.sqrt(3)/2*(eta[:] - eta[N-1])))) 
      to_be_minimized = np.sum(g[:])/N - 1
      return to_be_minimized
  
  result_of_minimization = minimize(my_minimization_func, 0.1, options={'gtol': 1e-8, 'disp': True})
  alpha_at_min = result_of_minimization.x
  print(alpha_at_min)
  </code></pre>